mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Hugetlb: stop race when reading proc meminfo
@ 2008-06-19 18:15 Eric Paris
  2008-07-02 22:51 ` Nish Aravamudan
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Paris @ 2008-06-19 18:15 UTC (permalink / raw)
  To: wli; +Cc: linux-kernel

minor nit that hugetlb_report_{,node_}meminfo() does not lock the
reading of nr_huge_pages, free_huge_pages, and friends so this is not an
atomic set of information put into the buffer.  If /proc/meminfo is read
while the number of hugetlb pages is in flux it is possible to get
incorrect output such as:

HugePages_Total:     7
HugePages_Free:      8
HugePages_Rsvd:      0
Hugepagesize:     4096 kB

(test available at https://bugzilla.redhat.com/attachment.cgi?id=309864)

With the patch we beat on a number of boxes for hours with the above
test and saw no inconsistencies in the meminfo output.

Signed-off-by: Eric Paris <eparis@redhat.com>

---

 mm/hugetlb.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index ab17127..fe074d1 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -687,7 +687,9 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
 
 int hugetlb_report_meminfo(char *buf)
 {
-	return sprintf(buf,
+	int ret;
+	spin_lock(&hugetlb_lock);
+	ret = sprintf(buf,
 			"HugePages_Total: %5lu\n"
 			"HugePages_Free:  %5lu\n"
 			"HugePages_Rsvd:  %5lu\n"
@@ -698,17 +700,23 @@ int hugetlb_report_meminfo(char *buf)
 			resv_huge_pages,
 			surplus_huge_pages,
 			HPAGE_SIZE/1024);
+	spin_unlock(&hugetlb_lock);
+	return ret;
 }
 
 int hugetlb_report_node_meminfo(int nid, char *buf)
 {
-	return sprintf(buf,
+	int ret;
+	spin_lock(&hugetlb_lock);
+	ret = sprintf(buf,
 		"Node %d HugePages_Total: %5u\n"
 		"Node %d HugePages_Free:  %5u\n"
 		"Node %d HugePages_Surp:  %5u\n",
 		nid, nr_huge_pages_node[nid],
 		nid, free_huge_pages_node[nid],
 		nid, surplus_huge_pages_node[nid]);
+	spin_unlock(&hugetlb_lock);
+	return ret;
 }
 
 /* Return the number pages of memory we physically have, in PAGE_SIZE units. */



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-07-08 13:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-19 18:15 [PATCH] Hugetlb: stop race when reading proc meminfo Eric Paris
2008-07-02 22:51 ` Nish Aravamudan
2008-07-03 14:13   ` Adam Litke
2008-07-08 13:51     ` Eric Paris

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®