Re: Jbd2 async problem

2018-01-22 Thread Rock Lee
Hi:

> Consider the case of 75 metadata blocks in the journal, with one bad block.
>
> Which results in less total damage when the journal is replayed:
>
> 1) Applying the 74 good ones (if possible) and complain about the one bad one?
>
> 2) Refusing to deal with *any* of them.

Indeed, I would like to choose 1) to keep my filesystem from less
damage. However, a transaction means the whole operation is atomic, it
could not be seperated in replay. If bad blocks could just be ignore,
there's no need of descriptor + commit pair, just copy crc right
blocks back to filesystem could achieve our goals.

-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Jbd2 async problem

2018-01-22 Thread Rock Lee
Hi:

I am working on jbd2 with checksum v3, trying to learn something from
the async feature. However, when I read the replay process in
do_one_process(), I got a little confused.

When async is on, commit blocks have the chance to reach the disk
before metadata blocks(which are on BJ_Shadow). If just at this
moment, power cutting occurs. Next mount time, we have to recovery
journal. Since checksum v3 is been chosen, metadata could be copyed to
filesystem one by one, if the metadata block has the right crc value.
But in the scenario I described before, commit block may reached disk
before some metadata blocks in a transaction. Current jbd2 code(linux
4.15) just skips those metadata blocks which have no correct crc, and
still copies the metadata blocks with the right crc.

I think in order to keep the consistency, the whole transaction should
be discarded, as long as not all the metadata blocks have the right
crc value in the transaction. But why jbd2 still copies the metadata
block(with the right crc) to filesystem when bad crc metadata blocks
exist ?

I will appreciate it if you could help me.

-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: sched_child_runs_first doesn't work

2017-12-10 Thread Rock Lee
On Sat, Dec 9, 2017 at 11:42 PM, strongbox8  wrote:
> in my test, it has a chance to get the output from the child first using the
> taskset command. otherwise, the child and the parent are always on different
> cores in which case i think the parent is running and the child is on the
> rbtree of runqueue of other core just after fork at the most moment
>

Your explanation is right. Child process doesn't have chance to run
util parent's time slice is over(Even though there's no time slice
concept in CFS). From the print, it looked like parent process run
first. So we need force parent and child process re-schedule before
print, so that child prcess have the chance to compare "vruntime" with
parent process. In this situation, we could see child process run
first. I modified the test code like this, "sleep (1);" added :

#include 
#include 
#include 

int main(void)
{
struct timeval tv;
struct timezone tz;
int err;
pid_t ret = fork();

sleep(1);

if (ret == 0) {
err = gettimeofday(, );
if (!err)
printf("child time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);

 printf("this child.\n");
} else if (ret > 1) {
err = gettimeofday(, );

if (!err)
printf("father time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);
printf("this father.\n");
} else
printf("err!!\n");
return 0;
}

Executed this app like this:

# taskset 1 ./fork

In the end, I could get child prcess run first sometimes.

-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: sched_child_runs_first doesn't work

2017-12-08 Thread Rock Lee
Hi,
I tried a test in that code without any gettimeofday, the result is
the same. BTW, I've tried on my raspberrpi 3 with kernel 4.13.
Moreover, I also tried several ubuntu 16.04. The result were always
father process ran first.

On Fri, Dec 8, 2017 at 1:53 PM, Mulyadi Santosa
<mulyadi.sant...@gmail.com> wrote:
>
>
> On Fri, Dec 8, 2017 at 10:07 AM, Rock Lee <rockdot...@gmail.com> wrote:
>>
>> Hi,
>>
>> I ran my test code but always got the father process run first, even
>> after setting sched_child_runs_first. Could anyone give me a hint?
>> Here is my test code.
>>
>> #include 
>> #include 
>> #include 
>>
>> int main(void)
>> {
>> struct timeval tv;
>> struct timezone tz;
>> int err;
>> pid_t ret = fork();
>>
>> if (ret == 0) {
>> err = gettimeofday(, );
>> if (!err)
>> printf("child time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);
>>
>>  printf("this child.\n");
>> } else if (ret > 1) {
>> err = gettimeofday(, );
>>
>> if (!err)
>> printf("father time sec %d, usec %d\n", tv.tv_sec,
>> tv.tv_usec);
>> printf("this father.\n");
>> } else
>> printf("err!!\n");
>> return 0;
>> }
>>
>>
>> --
>> Cheers,
>> Rock
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
>
> Hi...
>
> IIRC, gettimeofday() will eventually call system call (with the same name, I
> think). And I guess this is where the root cause come.
>
> Your child might actually ran first, but since it called system call,
> re-scheduling the kicked in, and parent got the chance to run.
>
> In order to prove this theory, try to execute printf("this is parent") or
> printf("this is child") first, then gettimeofday() later.
>
> Good luck and cmiiw
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com



-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: sched_child_runs_first doesn't work

2017-12-08 Thread Rock Lee
Hi,
I know the vfork guarantees the children run first. I am just curious
why sched_child_runs_first doesn't work. If there is a chance that
child process run first, I would be more glade, since I guess that how
it works, works with probability. However I tried more the 30+ times,
the result was always father process ran first. Eventhough I have't
tried that much, I guess my result still told the truth ---
sched_child_runs_first doesn't work at all.

On Fri, Dec 8, 2017 at 3:50 PM, Alexander Kapshuk
 wrote:
> If  my understanding of what Linus says in the post referenced below
> is correct, there's never a guarantee which process would run first,
> parent or child.
> http://yarchive.net/comp/linux/child-runs-first.html
>
> vfork(), on the other hand, is said in the post to always run the
> child process first. See below for an example.
> #include 
> #include 
> #include 
> #include 
>
> int main(void)
> {
> struct timeval tv;
>
> switch(vfork()) {
> case -1:
> perror("vfork failed\n");
> exit(-1);
> case 0:
> if (gettimeofday(, NULL) == 0)
> printf("child time sec %ld, usec %ld\n",
> tv.tv_sec, tv.tv_usec);
> exit(0);
> default:
> if (gettimeofday(, NULL) == 0)
> printf("parent time sec %ld, usec %ld\n",
> tv.tv_sec, tv.tv_usec);
> }
> return 0;
> }
>
> Sample run:
> ./gettimeofday
> child time sec 1512719270, usec 716672
> parent time sec 1512719270, usec 716748



-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


sched_child_runs_first doesn't work

2017-12-07 Thread Rock Lee
Hi,

I ran my test code but always got the father process run first, even
after setting sched_child_runs_first. Could anyone give me a hint?
Here is my test code.

#include 
#include 
#include 

int main(void)
{
struct timeval tv;
struct timezone tz;
int err;
pid_t ret = fork();

if (ret == 0) {
err = gettimeofday(, );
if (!err)
printf("child time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);

 printf("this child.\n");
} else if (ret > 1) {
err = gettimeofday(, );

if (!err)
printf("father time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);
printf("this father.\n");
} else
printf("err!!\n");
return 0;
}


-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: OOM killer hung the whole system

2017-07-31 Thread Rock Lee
On Mon, Jul 31, 2017 at 3:56 AM, Ruben Safir  wrote:

> On 07/30/2017 03:51 PM, Mulyadi Santosa wrote:
> > ust malloc() without free().
>
>
> and that surprises you?
>
> Yes, it suprised me. Since I ran this malloc() without free() on my laptop
and raspberrypi, there was no hang. This process would be killed and the
whole system survived.


-- 
Cheers,
Rock
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: OOM killer hung the whole system

2017-07-31 Thread Rock Lee
On Tue, Jul 25, 2017 at 7:29 PM, Yubin Ruan <ablacktsh...@gmail.com> wrote:

> 2017-07-25 17:59 GMT+08:00 Rock Lee <rockdot...@gmail.com>:
> > Hi,
> >
> > I was using a program to test OOM killer, but OOM killer hung my board.
> The
> > test snippet is very simple, just malloc() without free().
> >
> >   6 int i=0;
> >   7 char *ptrtest=NULL;
> >   8  while (1)
> >   9  {
> >  10ptrtest = malloc(0x1000);
> >  11if (ptrtest == NULL)
> >  12printf("malloc failed.\n");
> >  13  }
> >  14  return 0;
> >  15
> >
> > After I executed this program(a.out), there is no reaction of my shell.
> Only
> > this messege was shown:
> >
> > [  180.138188] Out of memory: Kill process 2706 (qq) score 623 or
> sacrifice
> > child
> > [  180.164230] Killed process 2706 (qq) total-vm:98156kB,
> anon-rss:96400kB,
> > file-rss:4kB
> >
> > I think it must be some problem with OOM killer, and tried a lot of way
> to
> > get some infomation. And I got this:
> >
> > ===
> > Process: a.out, cpu: 0 pid: 1463 start: 0xd5849b00
> > =
> > Task name: a.out pid: 1463 cpu: 0
> > state: 0x2 exit_state: 0x0 stack base: 0xd619
> > Stack:
> > [] __schedule+0x2c8
> > [] squashfs_cache_get+0x108
> > [] squashfs_readpage_block+0x28
> > [] squashfs_readpage+0x624
> > [] __do_page_cache_readahead+0x228
> > [] filemap_fault+0x1d4
> > [] __do_fault+0x34
> > [] do_read_fault+0x19c
> > [] handle_mm_fault+0x468
> > [] do_page_fault+0x11c
> > [] do_PrefetchAbort+0x34
> > [] ret_from_exception+0x0
> >
> > I am suprised, because a.out is in /tmp, there is no relation between
> a.out
> > and squashfs(my rootfs). Could anyone give me a hint ? Is the problem of
> > squashfs or OOM killer.
>
> You say your rootfs is squashfs filesystem. Is /tmp using the same
> device and same filesystem (i.e., squashfs) ?


Not exactly, /tmp uses tmpfs, but my rootfs uses squashfs.



-- 
Cheers,
Rock
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: OOM killer hung the whole system

2017-07-31 Thread Rock Lee
On Mon, Jul 31, 2017 at 3:51 AM, Mulyadi Santosa <mulyadi.sant...@gmail.com>
wrote:

>
>
> On Tue, Jul 25, 2017 at 4:59 PM, Rock Lee <rockdot...@gmail.com> wrote:
>
>> Hi,
>>
>> I was using a program to test OOM killer, but OOM killer hung my board.
>> The test snippet is very simple, just malloc() without free().
>>
>>   6 int i=0;
>>   7 char *ptrtest=NULL;
>>   8  while (1)
>>   9  {
>>  10ptrtest = malloc(0x1000);
>>  11if (ptrtest == NULL)
>>  12printf("malloc failed.\n");
>>  13  }
>>  14  return 0;
>>  15
>>
>> After I executed this program(a.out), there is no reaction of my shell.
>> Only this messege was shown:
>>
>> [  180.138188] Out of memory: Kill process 2706 (qq) score 623 or
>> sacrifice child
>> [  180.164230] Killed process 2706 (qq) total-vm:98156kB,
>> anon-rss:96400kB, file-rss:4kB
>>
>>
> I think the clue is above. Could you find out what is the process with pid
> 2706?
>
> I bet that is the shell that runs as the parent of your a.out program, but
> feel free to make sure what that is.
>

Sorry, my bad, it is a spelling mistake. a.out is actually qq  (pid 2706)


>
>
>
>> I think it must be some problem with OOM killer, and tried a lot of way
>> to get some infomation. And I got this:
>>
>> ===
>> Process: a.out, cpu: 0 pid: 1463 start: 0xd5849b00
>> =
>> Task name: a.out pid: 1463 cpu: 0
>> state: 0x2 exit_state: 0x0 stack base: 0xd619
>> Stack:
>> [] __schedule+0x2c8
>> [] squashfs_cache_get+0x108
>> [] squashfs_readpage_block+0x28
>> [] squashfs_readpage+0x624
>> [] __do_page_cache_readahead+0x228
>> [] filemap_fault+0x1d4
>> [] __do_fault+0x34
>> [] do_read_fault+0x19c
>> [] handle_mm_fault+0x468
>> [] do_page_fault+0x11c
>> [] do_PrefetchAbort+0x34
>> [] ret_from_exception+0x0
>>
>> I am suprised, because a.out is in /tmp, there is no relation between
>> a.out and squashfs(my rootfs). Could anyone give me a hint ? Is the problem
>> of squashfs or OOM killer.
>>
>
> The above stack trace just mention what happened in kernel space. Very
> likely when it was about to be killled by OOM killer. CMIIW.
>
> Thus, it has little or nothing to do with the fact that it called squash
> fs related function
>

There is a chance squashfs functions will be called when out of memory. It
is when a libary file is mmaped, filemap_fault() gave me a hint.


>
>
>
> --
> regards,
>
> Mulyadi Santosa
> Freelance Linux trainer and consultant
>
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
>
>
> <https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail>
>  Virus-free.
> www.avast.com
> <https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail>
> <#m_-5780323552132534074_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>


-- 
Cheers,
Rock
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


OOM killer hung the whole system

2017-07-25 Thread Rock Lee
Hi,

I was using a program to test OOM killer, but OOM killer hung my board.
The test snippet is very simple, just malloc() without free().

  6 int i=0;
  7 char *ptrtest=NULL;
  8  while (1)
  9  {
 10ptrtest = malloc(0x1000);
 11if (ptrtest == NULL)
 12printf("malloc failed.\n");
 13  }
 14  return 0;
 15

After I executed this program(a.out), there is no reaction of my shell.
Only this messege was shown:

[  180.138188] Out of memory: Kill process 2706 (qq) score 623 or sacrifice
child
[  180.164230] Killed process 2706 (qq) total-vm:98156kB, anon-rss:96400kB,
file-rss:4kB

I think it must be some problem with OOM killer, and tried a lot of way to
get some infomation. And I got this:

===
Process: a.out, cpu: 0 pid: 1463 start: 0xd5849b00
=
Task name: a.out pid: 1463 cpu: 0
state: 0x2 exit_state: 0x0 stack base: 0xd619
Stack:
[] __schedule+0x2c8
[] squashfs_cache_get+0x108
[] squashfs_readpage_block+0x28
[] squashfs_readpage+0x624
[] __do_page_cache_readahead+0x228
[] filemap_fault+0x1d4
[] __do_fault+0x34
[] do_read_fault+0x19c
[] handle_mm_fault+0x468
[] do_page_fault+0x11c
[] do_PrefetchAbort+0x34
[] ret_from_exception+0x0

I am suprised, because a.out is in /tmp, there is no relation between a.out
and squashfs(my rootfs). Could anyone give me a hint ? Is the problem of
squashfs or OOM killer.
-- 
Cheers,
Rock
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: How to get patches from e-mail client?

2017-04-17 Thread Rock Lee
Hi
Thank you guys, it works. But if there are series patches(like
[RFC][PATCH 00/13], [RFC][PATCH 01/13], [RFC][PATCH 02/13]), how
can I merge them quickly? I mean, I don't want to save and merge these
patches one by one.

On Mon, Apr 17, 2017 at 4:16 PM, Nicholas Mc Guire <der.h...@hofr.at> wrote:
> On Mon, Apr 17, 2017 at 08:02:32AM +, Amit Kumar wrote:
>> On Mon, Apr 17, 2017 at 03:52:42PM +0800, Rock Lee wrote:
>> > Hi:
>> > If I want to get a patch and use "git am" to merge it into my project,
>> > how can I do? I mean I can copy and paste a patch from my e-mail
>> > client, but it is too silly. Is there any way to save a email as a
>> > patch?
>> Run mutt. Select the patch you want to download using up/down arrow key.
>> Press s. Delete the mailbox name provide using Backspace key and provide
>> path on local filesystem e.g. ~/patches/logical_name.patch. It will ask
>> to save, yes is default, so press Enter.
>>
>> Now your patch is saved on local filesystem. Create a topic branch e.g.
>> Your on master,
>> git checkout -b work
>>
>> Now you are on topic branch work, run as follows,
>>
>> git am ~/patches/logical_name.patch
>>
>> If you are on the right tree then it should apply the patch and commit.
>> If something goes wrong, please follow the instructions provided by git.
>>
>> I think this will help.
>>
> you can simplify this in mutt by adding:
>
> macro index A '| git am -s'
>
> to your ~/.muttrc
> To apply a patch simply move into the repository you want to
> work on open mutt and hit  A  at that email to pipe it into
> git am -s  and apply it.
>
> thx!
> hofrat



-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


How to get patches from e-mail client?

2017-04-17 Thread Rock Lee
Hi:
If I want to get a patch and use "git am" to merge it into my project,
how can I do? I mean I can copy and paste a patch from my e-mail
client, but it is too silly. Is there any way to save a email as a
patch?

-- 
Cheers,
Rock

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


[no subject]

2015-10-21 Thread Rock Lee
unsubscribe kernelnewbies

Regards

Rock Lee  ___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Use a variable before it's declaration

2015-09-10 Thread Rock Lee
Hi, all:
Here is a snippet of linux-v3.4 which drives me crazy.
Because init_task hasn't been declared yet when init_thread_union is 
initializing. Why is there no compiling error? Any hint would be helpful.

union thread_union init_thread_union __init_task_data = 

 { INIT_THREAD_INFO(init_task) }; 

 

/* 

  * Initial task structure. 

  * 

  * All other task structs will be allocated on slabs in fork.c 

  */ 

struct task_struct init_task = INIT_TASK(init_task);


-- 
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Use a variable before it's declaration

2015-09-10 Thread Rock Lee
On 2015/9/10 15:55, valdis.kletni...@vt.edu wrote:
> On Thu, 10 Sep 2015 15:09:42 +0800, Rock Lee said:
>
>> union thread_union init_thread_union __init_task_data =
>>
>>   { INIT_THREAD_INFO(init_task) };
>
> 'gcc -E' to see what this expands to.  All may not be as it seems. :)
>

Thanks, I used "make arch/arm/kernel/init_task.i" instead to see what 
that code expands to. It's exactly what confused me still. 
init_thread_union uses init_task before init_task's initialization.

union thread_union init_thread_union 
__attribute__((__section__(".data..init_task"))) =
  { { .task = _task, .exec_domain = _exec_domain, .flags = 
0, .preempt_count = (1 + 0x4000), .addr_limit = 0x, 
.cpu_domain = ((3) << (2*(1))) | ((3) << (2*(0))) | ((1) << (2*(2))), 
.restart_block = { .fn = do_no_restart_syscall, }, } };


struct task_struct init_task = { .state = 0, .stack = 
&(init_thread_union.thread_info), .usage = { (2) }, .flags = 0x0020, 
.prio = (100 + 40)-20, .static_prio = (100 + 40)-20, .normal_prio = (100 
+ 40)-20, .policy = 0, .cpus_allowed = (cpumask_t) { { [(((1) + (8 * 
sizeof(long)) - 1) / (8 * sizeof(long)))-1] = ( ((1) % 32) ? (1UL<<((1) 
% 32))-1 : ~0UL ) } }, .mm = ((void *)0), .active_mm = _mm, .se = { 
.group_node = { &(init_task.se.group_node), &(init_task.se.group_node) 
}, }, .rt = { .run_list = { &(init_task.rt.run_list), 
&(init_task.rt.run_list) }, .time_slice = (100 * 100 / 1000), 
.nr_cpus_allowed = 1, }, .tasks = { &(init_task.tasks), 
&(init_task.tasks) }, .ptraced = { &(init_task.ptraced), 
&(init_task.ptraced) }, .ptrace_entry = { &(init_task.ptrace_entry), 
&(init_task.ptrace_entry) }, .real_parent = _task, .parent = 
_task, .children = { &(init_task.children), &(init_task.children) 
}, .sibling = { &(init_task.sibling), &(init_task.sibling) }, 
.group_leader = _task, .real_cred = (typeof(*_cred) 
*)(_cred), .cred = (typeof(*_cred) *)(_cred), .comm = 
"swapper", .thread = { }, .fs = _fs, .files = _files, .signal 
= _signals, .sighand = _sighand, .nsproxy = _nsproxy, 
.pending = { .list = { &(init_task.pending.list), 
&(init_task.pending.list) }, .signal = {{0}}}, .blocked = {{0}}, 
.alloc_lock = (spinlock_t ) { { .rlock = { .raw_lock = { 1 }, .magic = 
0xdead4ead, .owner_cpu = -1, .owner = ((void *)-1L), } } }, 
.journal_info = ((void *)0), .cpu_timers = { { 
&(init_task.cpu_timers[0]), &(init_task.cpu_timers[0]) }, { 
&(init_task.cpu_timers[1]), &(init_task.cpu_timers[1]) }, { 
&(init_task.cpu_timers[2]), &(init_task.cpu_timers[2]) }, }, .pi_lock = 
(raw_spinlock_t) { .raw_lock = { 1 }, .magic = 0xdead4ead, .owner_cpu = 
-1, .owner = ((void *)-1L), }, .timer_slack_ns = 5, .pids = { 
[PIDTYPE_PID] = { .node = { .next = ((void *)0), .pprev = ((void *)0), 
}, .pid = _struct_pid, }, [PIDTYPE_PGID] = { .node = { .next = 
((void *)0), .pprev = ((void *)0), }, .pid = _struct_pid, }, 
[PIDTYPE_SID] = { .node = { .next = ((void *)0), .pprev = ((void *)0), 
}, .pid = _struct_pid, }, }, .thread_group = { 
&(init_task.thread_group), &(init_task.thread_group) }, };

-- 
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Use a variable before it's declaration

2015-09-10 Thread Rock Lee
> Sure.  That's a completely different issue. But this works:
>
> extern int b;
> int *a = 
> int b = 20;
>
> int main(void)
> {
>   return 0;
> }
>
> and that's what the code you refer do does.

Yes, that make sense, thanks very much :-)
-- 
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Use a variable before it's declaration

2015-09-10 Thread Rock Lee
> Rock Lee <rocklee_...@outlook.com> writes:
>
>> Hi, all:
>>  Here is a snippet of linux-v3.4 which drives me crazy.
>> Because init_task hasn't been declared yet when init_thread_union is
>> initializing. Why is there no compiling error? Any hint would be helpful.
>>
>> union thread_union init_thread_union __init_task_data =
>>
>>   { INIT_THREAD_INFO(init_task) };
>>
>>
>>
>> /*
>>
>>* Initial task structure.
>>
>>*
>>
>>* All other task structs will be allocated on slabs in fork.c
>>
>>*/
>>
>> struct task_struct init_task = INIT_TASK(init_task);
>
>
> Because init_task is declared "extern" in linux/sched.h
>
>
> Bjørn

I do something like that:

extern int b;
int a = b + 10;
int b = 20;

int main(void)
{
return 0;
}

No doubt, compiling error.

-- 
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Where does the linux kernel put local variables

2015-08-04 Thread Rock Lee
Hi, Dave

 If you look at the linker script file for the kernel
 http://lxr.free-electrons.com/source/arch/arm/kernel/vmlinux.lds.S#L244
 , you'll see that INIT_TASK_DATA (which includes the kernel stack) is
 between _data and _edata. This is the stack used for kernel booting and
 then taken over by the init task.

Thanks for your advice ,after read 
http://lxr.free-electrons.com/source/arch/arm/kernel/head-common.S#L122, 
I'v got my answer.
-- 
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Where does the linux kernel put local variables

2015-08-03 Thread Rock Lee
Hi, all:
I print a local variable address in start_kernel(), and I realize this 
address is between __data_start and _edata. In my opinion,
local variables should be located in stack, why is this local variable 
located in data section? BTW, I use a arm11 board with linux-2.6.28.

Thanks
-- 
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question about struct block_device

2015-05-18 Thread Rock Lee
Hello:
In struct block_device, there are two counters, one is bd_openers, and 
the other is bd_part_count. Why do there need those
two counters? Can anybody give me some hint?

--
Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: maybe dumb question about RCU

2015-04-08 Thread Rock Lee
 From: Rock Lee [mailto:rocklee_...@outlook.com]
 Sent: Tuesday, April 07, 2015 7:09 PM
 To: Jeff Haran
 Cc: kernelnewbies
 Subject: Re: maybe dumb question about RCU


 256 If you are going to be fetching multiple fields from the

 257 RCU-protected structure, using the local variable is of

 258 course preferred.  Repeated rcu_dereference() calls look

 259 ugly and incur unnecessary overhead on Alpha CPUs.

   From lines 256 to 259 I conclude that reader()'s code is considered
 ugly and wasteful,

 but a will always equal b.

 But looking at how rcu_dereference() and rcu_assign_pointer() are
 implemented, I'm having a

 hard time seeing how reader() would always see a and b equal.



 This is the implementation of rcu_dereference(). It is a little old, but 
 useful as well.

 #define rcu_dereference(p) ({ \
  typeof(p) _p1 = ACCESS_ONCE(p); \
  smp_read_barrier_depends(); \
  (_p1); \
  })

 It uses memory barrier to guarantee the order of code execution.
 rcu_read_lock() actually disables preemption, so writer has no chance to 
 modify critical section in the rcu_read_lock()/rcu_read_unlock() pair.

 Thanks for getting back to me, Rock.

 Disabling preemption would prevent a writer on the same core as the reader 
 from changing the pointer in the read critical section.

 But what happens if the writer is running on another core of a multi-core 
 system?

 Seems like a writer on another core could still get in there and change the 
 value of the pointer between the two rcu_dereference() calls in the reader.

 Jeff Haran


Ys, rcu_read_lock() and rcu_read_unlock() calls never spin or block, 
nor do they prevent the writer from changing the value of the critical 
section concurrently.

I am still confused about this part, sorry. I think this article will 
help, although my poor English hasn't make me fully understand it.

http://lwn.net/Articles/262464/

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


scull_init_module() in scull driver

2015-04-07 Thread Rock Lee
Hi, guys:
I am reading function scull_init_module() in scull driver.I found that 
scull_init_module() doesn't check  scull_setup_cdev()'s return value.If 
there will be a probem when scull_setup_cdev() failed, and then, others 
call scull_cleanup_module()?

for (i = 0; i  scull_nr_devs; i++) {
scull_devices[i].quantum = scull_quantum;
scull_devices[i].qset = scull_qset;
init_MUTEX(scull_devices[i].sem);
scull_setup_cdev(scull_devices[i], i);
}

Best Regard

Rock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: maybe dumb question about RCU

2015-04-07 Thread Rock Lee

 256 If you are going to be fetching multiple fields from the

 257 RCU-protected structure, using the local variable is of

 258 course preferred.  Repeated rcu_dereference() calls look

 259 ugly and incur unnecessary overhead on Alpha CPUs.”

  From lines 256 to 259 I conclude that reader()’s code is considered
 ugly and wasteful,

 but a will always equal b.

 But looking at how rcu_dereference() and rcu_assign_pointer() are
 implemented, I’m having a

 hard time seeing how reader() would always see a and b equal.

This is the implementation of rcu_dereference(). It is a little old, but 
useful as well.

#define rcu_dereference(p) ({ \
typeof(p) _p1 = ACCESS_ONCE(p); \
smp_read_barrier_depends(); \
(_p1); \
})

It uses memory barrier to guarantee the order of code execution.
rcu_read_lock() actually disables preemption, so writer has no chance to 
modify critical section in the rcu_read_lock()/rcu_read_unlock() pair.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: cross-compiling kernel using a 32-bit toolchain on a 64-bit machine

2015-04-06 Thread Rock Lee


On 2015/4/7 6:50, Mandeep Sandhu wrote:
 Hi All,

 I'm having trouble compiling my kernel using a 32-bit toolchain (for
 ARM) on a 64-bit host (Ubuntu 14.10). The kernel version is 3.14.17.

 I understand that 32-bit binaries require ia32-libs (or equivalent)
 for compiling on 64-bit hosts. I installed the required packages
 (lib32z1 lib32ncurses5 lib32bz2-1.0 for Ubuntu 14.10), but still keep
 getting errors:

 $ make CROSS_COMPILE=arm-none-linux-gnueabi- all
 Makefile:616: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR:
 -fstack-protector not supported by compiler
 make: arm-none-linux-gnueabi-gcc: Command not found
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
 make[1]: `include/generated/mach-types.h' is up to date.
CC  kernel/bounds.s
 /bin/sh: 1: arm-none-linux-gnueabi-gcc: not found
 make[1]: *** [kernel/bounds.s] Error 127
 make: *** [prepare0] Error 2

 I've ensured that the PATH to the toolchain binaries is correct.

 If I try to export CROSS_COMPILE to my environment, then too I get an
 error (although it's for a different reason):

 $ make all
 Makefile:616: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR:
 -fstack-protector not supported by compiler
CHK include/config/kernel.release
CHK include/generated/uapi/linux/version.h
CHK include/generated/utsrelease.h
 make[1]: `include/generated/mach-types.h' is up to date.
CC  kernel/bounds.s
 gcc: error: unrecognized argument in option ‘-mabi=aapcs-linux’
 gcc: note: valid arguments to ‘-mabi=’ are: ms sysv
 gcc: error: unrecognized command line option ‘-mlittle-endian’
 gcc: error: unrecognized command line option ‘-mapcs’
 gcc: error: unrecognized command line option ‘-mno-sched-prolog’
 gcc: error: unrecognized command line option ‘-mno-thumb-interwork’
 gcc: error: unrecognized command line option ‘-mfpu=vfp’
 make[1]: *** [kernel/bounds.s] Error 1
 make: *** [prepare0] Error 2

 It looks like make is starting a new shell which does not have either
 PATH (1st case) or  CROSS_COMPILE (2nd case) set.

 Any hints on how to get make to use the toolchain?

 Thanks,
 -mandeep

 ___
 Kernelnewbies mailing list
 Kernelnewbies@kernelnewbies.org
 http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Edit .config and set  CONFIG_CROSS_COMPILE to the path where your cross 
compiler is located.

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Question abount bh_lru_lock()

2015-03-23 Thread Rock Lee
Hi, all:
Going through fs/buffer.c, I find that
bh_lru_lock() is a macro which can be local_irq_disable() or
preempt_disable().

#ifdef CONFIG_SMP
#define bh_lru_lock()   local_irq_disable()
#define bh_lru_unlock() local_irq_enable()
#else
#define bh_lru_lock()   preempt_disable()
#define bh_lru_unlock() preempt_enable()
#endif

In SMP system, bh_lru_lock just disables local interrupt, if current
kernel is preemptible, how can bh_lru_lock protect critical region?

or

In UP system, is making the kernel just non-preemptible safe enough when 
an interrupt occur and its handler may modify critical region?

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RCU is not safe enough to protect __d_lookup ?

2015-03-12 Thread Rock Lee

Hi, all:
I am studying the dcache in VFS recently . I've found that hlist of dcache is 
already protected by RCU in __d_lookup.Is it necessary  for the function -- 
d_lookup using sequence lock to protect the hlist again?
struct dentry * d_lookup(struct dentry * parent, struct qstr * name){   struct 
dentry * dentry = NULL;  unsigned long seq;
do {seq = read_seqbegin(rename_lock);
dentry = __d_lookup(parent, name);if (dentry)   
  break;  } while (read_seqretry(rename_lock, seq)); return dentry;}
Thanks in advanceRock Lee
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


RCU is not safe enough to protect __d_lookup ?

2015-03-12 Thread Rock Lee

Hi, all:
I am studying the dcache in VFS recently . I've found that hlist of dcache is 
already protected by RCU in __d_lookup.Is it necessary  for the function -- 
d_lookup using sequence lock to protect the hlist again?
struct dentry * d_lookup(struct dentry * parent, struct qstr * name){   struct 
dentry * dentry = NULL;  unsigned long seq;
do {seq = read_seqbegin(rename_lock);
dentry = __d_lookup(parent, name);if (dentry)   
  break;  } while (read_seqretry(rename_lock, seq)); return dentry;}
Thanks in advanceRock Lee
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Kernel preemption

2015-03-11 Thread Rock Lee
Hi, guys:

I have a device with only one CPU. I am wondering whether there 
will be only one task running on CPU and this task will not be 
interrupted by scheduler if I make the kernel non-preemptive ? At this 
situation, whether the time splice will not exist?



Regards



---

Rock Lee 
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


The limits of move operation in shared-subtree

2014-12-08 Thread Rock Lee
Hi, all:I am reading the implementation of shared-subtree in linux 
kernel. There are two limits about move operation confused me badly, I have 
read the design document -- Shared-Subtree Concept, Implementation, 
andApplications in Linux ,but still puzzled.
1.Why can't move a mount residing in a shared mounts?2.Why can't move a mount 
tree containing an unbindable mount to a shared mount?Is it not a good way to 
prune out unbindable mounts just like rbind semantics do?   Thanks in 
advanceRock Lee

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Why does register_block release a bdev_inode instance at the end?

2014-11-04 Thread Rock Lee


Hi, all:
It has been known that all inodes that represent block devices are kept 
on the bdev pseudo-filesystem.And I thought that a bdev_inode instance is 
generated when the function of register_disk is called.But why does 
register_disk release a bdev_inode instance by calling blkdev_put at the end? 
BTW, my kernel is linux-2.6.32.


RegardsRock Lee___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


How can I wake up one process from the wait queue?

2014-10-30 Thread Rock Lee
Hi, everyoneI am implementing a simple driver to experiment with wait queue.Two 
or more read processes block until a write process changes a flag and call 
wake_up_interruptible().I expect that a write process will only wake up one 
read process.However, once a write process calls  wake_up_interruptible() , all 
the read processes are awaken. How can I wake up one process from the wait 
queue? Here is the snippet of the simple dirver(just for experimenting, kernel 
2.6.18):
static ssize_t rlwait_read(struct file *filp, char __user *userp, size_t size, 
loff_t *off){struct rlwait_t *rock = (struct rlwait_t *)filp-private_data; 
   DECLARE_WAITQUEUE(wait, current);add_wait_queue(rock-r_wait_head, 
wait);while (rock-r_flag == 0) {
set_current_state(TASK_INTERRUPTIBLE);schedule();}   
remove_wait_queue(rock-r_wait_head, wait);
set_current_state(TASK_RUNNING);return 0;}
static ssize_t rlwait_write(struct file *filp, const char __user *userp, size_t 
size, loff_t *off){struct rlwait_t *rock = (struct rlwait_t 
*)filp-private_data;rock-r_flag = 1;
wake_up_interruptible(rock-r_wait_head);return size; }
Thans in advice.___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


回复:Re: How can I wake up one process from the wait queue?

2014-10-30 Thread Rock Lee
Hi, Raghavendra, pranjas:
Thanks for your reply, add_wait_queue_exclusive() is perfect.
- 原始邮件 -
发件人:Raghavendra ar...@cdac.in
收件人:kernelnewbies@kernelnewbies.org
主题:Re: How can I wake up one process from the wait queue?
日期:2014年10月30日 16点52分


  
  
On Thursday 30 October 2014 02:02 PM,
  Rock Lee wrote:



  Hi, everyone
  I am implementing a simple driver to experiment with wait
queue.Two or more read processes block until a write process
changes a flag and call wake_up_interruptible().I expect that a
write process will only wake up one read process.However, once a
write process calls  wake_up_interruptible() , all the read
  processes are awaken. How can I wake up one process
from the wait queue?

  

You can use exclusive wait queues, which wakes up only one process
from the queue.



Although the general idea that is followed is: all the process are
woken up once the resource is made available. And then the access to
that resource is guarded by a lock, which in turn allows only one
process to access the resource. Rest of the processes are pushed
backed to sleep(or busy wait).

  
---


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies