Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3472098imu; Sun, 11 Nov 2018 15:53:40 -0800 (PST) X-Google-Smtp-Source: AJdET5cvEjYbZY1wGh0zgqEcQ1dm8zxbXcvvbeTz3Uhj/UT8uhgpvDZwagdShCedqWjWv9kzPp4X X-Received: by 2002:a17:902:4025:: with SMTP id b34-v6mr18024972pld.318.1541980420533; Sun, 11 Nov 2018 15:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980420; cv=none; d=google.com; s=arc-20160816; b=Ap8oA3YgaYvgP0irdrs6Fx4w0NKYQjg7b7YzXl5tL5J9XtMGhHvo5W+otNR7PFnDM7 hZ6OXmXWt3XPelzF4lnBbECBuX46AiZCeKqPuEkFz77kI+xMNOsf9t51hjhixlEdHk+2 5ZYP/OpARXuKfRl2IFIOa85jXsu+ChSsadnCYpowLA8QcW9RySxFdnY5eL51ULk+hS91 nVzj/LcQ9ku5ma3biqAth0oj5HQF9t6JLsRLVKNGJHxgy9W7XyOMWdBskbFxxsZT/R/8 UupOPTmu/gWVCptrxpfH3KYnHY0jTLFJEUFwurWfGv0mvHuoY+AKG1/Ruya5yfAWkfZi TERg== 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=5tcveCiuCg5hBtmZMQFFUtgKvjOhRF1sSBDuWBxrVGc=; b=ycmJWxbMy3I7IYDWdwUVHO4M9jDxVOCKEJJW7jtdpZU0ImjR9FCVTRT1pTh7GQJTsR 20Y0G7UV6ceIAHaLm0JXPxOWileldVTLWFsVb4a9zeBO4ULiydpxUsmBD6JwerWjMLS4 jzcYjYcaDHv7+MkllYuAdeiBDAlUNidMOqSlCM/gEXDLAwMUKpTzc1xlmNYzOABkaVs/ 3LRueX5wrRZb5eD0zrZm0BG8ejmFUZxmzJlXmq4mgsTV23FWb9cFDl5nz3Pa6pJw0BS0 WAdjyjTbbMToWMnlFoo95smE3nLHCOw812pY7eJpK3eHt11qhGvtLXBvBY6HxhHMrh6A gXhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="o17/IVEk"; 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 a4-v6si17325381pln.67.2018.11.11.15.53.25; Sun, 11 Nov 2018 15:53:40 -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="o17/IVEk"; 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 S1732807AbeKLIS0 (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:37518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732788AbeKLISZ (ORCPT ); Mon, 12 Nov 2018 03:18:25 -0500 Received: from localhost (unknown [206.108.79.134]) (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 8674121508; Sun, 11 Nov 2018 22:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975309; bh=IzGQjBeLo7hVTgOMjVSiX5SjNYHBrNS27f9oWCBzYDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o17/IVEkHfSfBSI6nC4IN/iz+Y7bb92MvH+4nEBFSjw6qDJ6/om3Cpp0Xt/yojrsH kbCUQCY8BclCY3VvHARNyz4+Z8a2RthG2/x9qqYkpLYtM6GniGCt67sLOQ9zMIorKG f3X3HF+BvIOeT/hp8khQ1vntZjMxYVRx0QvhC0zw= 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.19 252/361] hugetlbfs: dirty pages as they are added to pagecache Date: Sun, 11 Nov 2018 14:19:59 -0800 Message-Id: <20181111221653.284125624@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@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.19-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 @@ -3690,6 +3690,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);