Skip to contentSkip to conversation

mm/hugetlb_cgroup: fix a -Wunused-but-set-variable

PATCH In review Qian Cai 2 participants 3 messages Feb 17, 2020 – Feb 18, 2020

Subsystems (2)
lore
Share & tools
lore

Qian Cai

author
#0 lore raw

PATCH 1/1 mm/hugetlb_cgroup: fix a -Wunused-but-set-variable

The commit c32300516047 ("hugetlb_cgroup: add interface for charge/uncharge hugetlb reservations") forgot to remove an unused variable,

mm/hugetlb_cgroup.c: In function 'hugetlb_cgroup_migrate':
mm/hugetlb_cgroup.c:777:25: warning: variable 'h_cg' set but not used [-Wunused-but-set-variable]

  struct hugetlb_cgroup *h_cg;
                         ^~~~
---
 mm/hugetlb_cgroup.c | 2 --
 1 file changed, 2 deletions(-)
mm/hugetlb_cgroup.c +0 -2
index ad777fecad28..8a86a2b62bef 100644
@@ -774,7 +774,6 @@ void __init hugetlb_cgroup_file_init(void)
  */
 void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
 {
-	struct hugetlb_cgroup *h_cg;
 	struct hugetlb_cgroup *h_cg_rsvd;
 	struct hstate *h = page_hstate(oldhpage);
 
@@ -783,7 +782,6 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
 
 	VM_BUG_ON_PAGE(!PageHuge(oldhpage), oldhpage);
 	spin_lock(&hugetlb_lock);
-	h_cg = hugetlb_cgroup_from_page(oldhpage);
 	h_cg_rsvd = hugetlb_cgroup_from_page_rsvd(oldhpage);
 	set_hugetlb_cgroup(oldhpage, NULL);
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 37 lines · Qian Cai

The commit c32300516047 ("hugetlb_cgroup: add interface for charge/uncharge hugetlb reservations") forgot to remove an unused variable,

mm/hugetlb_cgroup.c: In function 'hugetlb_cgroup_migrate':
mm/hugetlb_cgroup.c:777:25: warning: variable 'h_cg' set but not used [-Wunused-but-set-variable]

  struct hugetlb_cgroup *h_cg;
                         ^~~~
---
 mm/hugetlb_cgroup.c | 2 --
 1 file changed, 2 deletions(-)
mm/hugetlb_cgroup.c +0 -3
index ad777fecad28..8a86a2b62bef 100644
@@ -774,7 +774,6 @@ void __init hugetlb_cgroup_file_init(void)
  */
 void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
 {
-       struct hugetlb_cgroup *h_cg;
        struct hugetlb_cgroup *h_cg_rsvd;
        struct hstate *h = page_hstate(oldhpage);
 
@@ -783,7 +782,6 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
 
        VM_BUG_ON_PAGE(!PageHuge(oldhpage), oldhpage);
        spin_lock(&hugetlb_lock);
-       h_cg = hugetlb_cgroup_from_page(oldhpage);
        h_cg_rsvd = hugetlb_cgroup_from_page_rsvd(oldhpage);
        set_hugetlb_cgroup(oldhpage, NULL);
 
--
Quoted 2 lines

1.8.3.1

Hi Qian,

Thank you very much for the fix to remove the warning, but actually the real fix is I'm missing a 'set_hugetlb_cgroup(newhpage, h_cg);' which will use the variable and set the cgroup on newhpage which is needed. I'll submit the proper fix.

What bothers me though is that locally when I checkout the broken patch and try to build I don't see the warning:

make -j80 mm/hugetlb_cgroup.o
no warning.
make -j80 mm/hugetlb_cgroup.o CFLAGS_KERNEL="-Wall"
no warning
make -j80 mm/hugetlb_cgroup.o CFLAGS_KERNEL="-Wunused-but-set-variable" I see the warning.

So it seems there is a bunch of warnings I need to explicitly turn on otherwise I will continually submit patches that introduce warnings in your build. Any idea why I'm running into this? Do you also have to turn on these warnings manually on your make line? Is it related to gcc version? My gcc version is:
gcc version 9.2.1 20190909 (Debian 9.2.1-8)

author
#2 lore raw
Quoted 58 lines · Mina Almasry
Quoted 37 lines · Qian Cai

The commit c32300516047 ("hugetlb_cgroup: add interface for charge/uncharge hugetlb reservations") forgot to remove an unused variable,

mm/hugetlb_cgroup.c: In function 'hugetlb_cgroup_migrate':
mm/hugetlb_cgroup.c:777:25: warning: variable 'h_cg' set but not used [-Wunused-but-set-variable]

  struct hugetlb_cgroup *h_cg;
                         ^~~~
---
 mm/hugetlb_cgroup.c | 2 --
 1 file changed, 2 deletions(-)
mm/hugetlb_cgroup.c +0 -3
index ad777fecad28..8a86a2b62bef 100644
@@ -774,7 +774,6 @@ void __init hugetlb_cgroup_file_init(void)
  */
 void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
 {
-       struct hugetlb_cgroup *h_cg;
        struct hugetlb_cgroup *h_cg_rsvd;
        struct hstate *h = page_hstate(oldhpage);
 
@@ -783,7 +782,6 @@ void hugetlb_cgroup_migrate(struct page *oldhpage, struct page *newhpage)
 
        VM_BUG_ON_PAGE(!PageHuge(oldhpage), oldhpage);
        spin_lock(&hugetlb_lock);
-       h_cg = hugetlb_cgroup_from_page(oldhpage);
        h_cg_rsvd = hugetlb_cgroup_from_page_rsvd(oldhpage);
        set_hugetlb_cgroup(oldhpage, NULL);
 
--
Quoted 2 lines

1.8.3.1

Hi Qian,

Thank you very much for the fix to remove the warning, but actually the real fix is I'm missing a 'set_hugetlb_cgroup(newhpage, h_cg);' which will use the variable and set the cgroup on newhpage which is needed. I'll submit the proper fix.

What bothers me though is that locally when I checkout the broken patch and try to build I don't see the warning:

make -j80 mm/hugetlb_cgroup.o
no warning.
make -j80 mm/hugetlb_cgroup.o CFLAGS_KERNEL="-Wall"
no warning
make -j80 mm/hugetlb_cgroup.o CFLAGS_KERNEL="-Wunused-but-set-variable" I see the warning.

Quoted 6 lines

So it seems there is a bunch of warnings I need to explicitly turn on otherwise I will continually submit patches that introduce warnings in your build. Any idea why I'm running into this? Do you also have to turn on these warnings manually on your make line? Is it related to gcc version? My gcc version is:
gcc version 9.2.1 20190909 (Debian 9.2.1-8)

I am doing "make W=1" which will turn on those warnings. Quite noisy but you can "grep" what you are interested in.