Kernel Newbies archive on lore.kernel.org
 help / color / Atom feed
From: "Máté Eckl" <ecklm94@gmail.com>
To: Amit Kumar <free.amit.kumar@gmail.com>
Cc: linux-newbie@vger.kernel.org,
	Kernel Newbies <kernelnewbies@kernelnewbies.org>
Subject: Re: Unable to understand a piece of code
Date: Wed, 22 May 2019 19:57:59 +0200
Message-ID: <20190522175759.4ganjslc6mooxrcp@sch.bme.hu> (raw)
In-Reply-To: <CAPTh4Ouvn=SiGnUGV5B7Drmp2-tVCMV=Z46+t-XL5rqPcTpF-g@mail.gmail.com>

On Mon, May 20, 2019 at 05:37:41AM +0530, Amit Kumar wrote:
> HI,
> 
> mm/slub.c: line 3973
> int __kmem_cache_shrink(struct kmem_cache *s)
> {
> int node;
> int i;
> struct kmem_cache_node *n;
> struct page *page;
> struct page *t;
> struct list_head discard;
> struct list_head promote[SHRINK_PROMOTE_MAX];
> unsigned long flags;
> int ret = 0;
> 
> flush_all(s);
> for_each_kmem_cache_node(s, node, n) {
> 
> How uninitialized variable node is being used in macro for_each_kmem_cache_node?
> 
> node is a local variable with no extern and not initialized.
> 
> mm/slab.h: line 490
> #define for_each_kmem_cache_node(__s, __node, __n) \
> for (__node = 0; __node < nr_node_ids; __node++) \
> if ((__n = get_node(__s, __node)))
> 
> As we see for loop is based on node.

Hi,

This sentence is almost correct. The for loop is *not based* on node but *uses*
the node variable. If you check, __node gets initialised to 0 at the beginning of
the for loop. So whatever you use that macro with will be initialised to 0 at
the beginning of the for loop.

Bests,
Máté

> 
> Thanks in advance.
> 
> Regards,
> Amit Kumar

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

      parent reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-20  0:07 Amit Kumar
2019-05-20  1:23 ` Tobin C. Harding
2019-05-20  3:33   ` Amit Kumar
2019-05-22 17:57 ` Máté Eckl [this message]

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190522175759.4ganjslc6mooxrcp@sch.bme.hu \
    --to=ecklm94@gmail.com \
    --cc=free.amit.kumar@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=linux-newbie@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Kernel Newbies archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernelnewbies/0 kernelnewbies/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernelnewbies kernelnewbies/ https://lore.kernel.org/kernelnewbies \
		kernelnewbies@kernelnewbies.org kernelnewbies@archiver.kernel.org
	public-inbox-index kernelnewbies


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernelnewbies.kernelnewbies


AGPL code for this site: git clone https://public-inbox.org/ public-inbox