Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2983647imu; Mon, 19 Nov 2018 08:59:15 -0800 (PST) X-Google-Smtp-Source: AJdET5dw/gUybnk1TBqUJGlp1iyc/ZD6SwZhxbx/QYF3WxHYz43fReK8PbyPS5Ta8p+bgOonLroO X-Received: by 2002:a63:741:: with SMTP id 62mr20156039pgh.352.1542646755504; Mon, 19 Nov 2018 08:59:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646755; cv=none; d=google.com; s=arc-20160816; b=uGHbq301OmeB55zXFVr2JY8NQWtPxVl27/3n9vLz+APiYw1bojJ6Qio4VRaLZkj6HN OPUEHUFFflbl4TkTr3f7HBtRuBMJX4uFgha5uLr/9U3YEaIaNM3y28VkKqtMICJZ2yjb sVKw0Owlt5xmelgnjxkLk7DPfTtkeuCDyw2uIQVMK6EfbUVF6YeZJ8y+z6tUnk7kaGOA tYGKVGBmQO3YY3KxphEDOVZCtDP4cuJB+dHBO+wn8VewNVy8dFHkZL4LfK1+KN09trOC S1sUwjOz3FZSeV1RuLIjZ+qltTbLSWEP7Gu7dwP5t/q+RIpAhb9gvuLHeCpU4jTHMggV VrHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gcY9/ga2yakRjcws5KypuRVHgkAYrFp82DVlnD5ih8w=; b=xKOIqbStzpskmSmSS0wuJ2e/jpM7OcYaDM44aAdcbrjmLKOPf7wLVjvM1UuZC9iuuW 6vTVGM3VGVhzcTVwHdOV4bUy7a6pjWxXwo05cdO6b20vGlSsymoDSxQhHdyvVUCZ7y5m wSNBtlUCiGFoVvIE5f19u7EEZYQofnba56Z+kfdljQ4bRbknmbm1v3lrmzXb4fFPmj7k FinIk8Cp8vjOfc7VcDjEIGdAxUcXWVvKbgqr52/F5B8imeCMTfS3QjpPCyygEL/PTK42 /R++/I71pleuMb0uGc09LVG4z/FDBWNbwCdlX7TTAASYx4YmKOZmLYMXAxNWX6+ZYbr1 OlVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qkTb3hIG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si37461754pgl.485.2018.11.19.08.59.00; Mon, 19 Nov 2018 08:59:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qkTb3hIG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404837AbeKTDWm (ORCPT + 99 others); Mon, 19 Nov 2018 22:22:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:34424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404112AbeKTDWl (ORCPT ); Mon, 19 Nov 2018 22:22:41 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 18FE42146D; Mon, 19 Nov 2018 16:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646705; bh=ejEnLAznzX3rMoW3x4VUFQ42Q5Oclj07dUfMO3mYKwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qkTb3hIGfSkwJldIhi7E580V9yWkLDFXe6E85zyS6oJBHPgY9UY4KOtNTZ8RYy405 V2BpIDfk6sOrPJaNv5TjnRMW7U+BcgAr3dvDfKOXlktU6ObQG5zkslxH2D92MiFXBy YDARGDsOzwrcrQHvrIKvQ8U8sUX8rPKtjv8YyAns= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Kravetz , Mihcla Hocko , Khalid Aziz , Hugh Dickins , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Alexander Viro , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 058/160] hugetlbfs: dirty pages as they are added to pagecache Date: Mon, 19 Nov 2018 17:28:17 +0100 Message-Id: <20181119162637.083162484@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162630.031306128@linuxfoundation.org> References: <20181119162630.031306128@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mike Kravetz commit 22146c3ce98962436e401f7b7016a6f664c9ffb5 upstream. Some test systems were experiencing negative huge page reserve counts and incorrect file block counts. This was traced to /proc/sys/vm/drop_caches removing clean pages from hugetlbfs file pagecaches. When non-hugetlbfs explicit code removes the pages, the appropriate accounting is not performed. This can be recreated as follows: fallocate -l 2M /dev/hugepages/foo echo 1 > /proc/sys/vm/drop_caches fallocate -l 2M /dev/hugepages/foo grep -i huge /proc/meminfo AnonHugePages: 0 kB ShmemHugePages: 0 kB HugePages_Total: 2048 HugePages_Free: 2047 HugePages_Rsvd: 18446744073709551615 HugePages_Surp: 0 Hugepagesize: 2048 kB Hugetlb: 4194304 kB ls -lsh /dev/hugepages/foo 4.0M -rw-r--r--. 1 root root 2.0M Oct 17 20:05 /dev/hugepages/foo To address this issue, dirty pages as they are added to pagecache. This can easily be reproduced with fallocate as shown above. Read faulted pages will eventually end up being marked dirty. But there is a window where they are clean and could be impacted by code such as drop_caches. So, just dirty them all as they are added to the pagecache. Link: http://lkml.kernel.org/r/b5be45b8-5afe-56cd-9482-28384699a049@oracle.com Fixes: 6bda666a03f0 ("hugepages: fold find_or_alloc_pages into huge_no_page()") Signed-off-by: Mike Kravetz Acked-by: Mihcla Hocko Reviewed-by: Khalid Aziz Cc: Hugh Dickins Cc: Naoya Horiguchi Cc: "Aneesh Kumar K . V" Cc: Andrea Arcangeli Cc: "Kirill A . Shutemov" Cc: Davidlohr Bueso Cc: Alexander Viro Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3537,6 +3537,12 @@ int huge_add_to_page_cache(struct page * return err; ClearPagePrivate(page); + /* + * set page dirty so that it will not be removed from cache/file + * by non-hugetlbfs specific code paths. + */ + set_page_dirty(page); + spin_lock(&inode->i_lock); inode->i_blocks += blocks_per_huge_page(h); spin_unlock(&inode->i_lock);