Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3430557imu; Sun, 11 Nov 2018 14:57:00 -0800 (PST) X-Google-Smtp-Source: AJdET5fqcGLk2UyCCKpEucCbjIl18ntrLwrlx/oatV6U3zE27S58wEaI+X6mgY7XM45keBjprSXn X-Received: by 2002:a62:3501:: with SMTP id c1-v6mr17663838pfa.173.1541977020479; Sun, 11 Nov 2018 14:57:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977020; cv=none; d=google.com; s=arc-20160816; b=A75ANSYnChYbq/CD6gANXinAUsa+SY/xh9jkB03hn+DyWGANz6EPb9rBS6hUwMm3fK j3rO8SbDpSHHxg6M3ITFO5T1rdUYFZ2Oir23pZWYHlUG6O4SNFYh61HpppI/QraHUCuZ XARmGbr9YVPuth8W+SeN02+7C1ppX0lmuhXgBCVQkGHb/n/uaIVWMMBpN7Vcj5Qf5Ctn ppSS3tUZkQEyJWFnzAxg16jTG+N8bUNwoqsU7OQq2LJJ0q1h2XOSvIWTRB2cWyU4YjCV ZfgRZRaMV2PiWFzTinasAQbPncJFlM5e51kkCyZQvf35jcLOIDt8ks22rDN0FxRAIn45 fkFg== 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=os85tDB/aWFUQeo2YaOgi79p9U98IDPga+JnSW5nStc=; b=woXtrdShhNIh7np3w1+WQl7ceMo44br3cBo0+rhTZ2Sz82pd5HZj+KUi0rtu1TUEMs x9v/5mg9l6Vrov7+oSHZIyJVuoLwxCH13W+UIl1+FYOQwS4UhLC4MHDm4XmzkhWFPwKu 0gIKq+1zj6lF2PO0Ldel0V1cx72EG/7BfxiajSUzPSTntl0lplGxEytQvN8LUFdEPOnf m9zUsW5ohyrSiuDTwZRi8bQyY0aioAyLu3tNOjHcznNH4gmZs54o4MUVfm6Wwy4QB94m Sg/I3+g8UcYlhfN3RDxvnvFnG2hmuuTlA4bF+Ha5A3xTWNokflnDuj2p65Rou8pq1skj I0NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D5gCBgel; 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 w6-v6si16231703pfn.212.2018.11.11.14.56.45; Sun, 11 Nov 2018 14:57:00 -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=D5gCBgel; 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 S2390893AbeKLIqQ (ORCPT + 99 others); Mon, 12 Nov 2018 03:46:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:54742 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729476AbeKLIWw (ORCPT ); Mon, 12 Nov 2018 03:22:52 -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 1558F223D8; Sun, 11 Nov 2018 22:32:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975575; bh=1W0n+tTLT2rZ8q1rpjHvs8vte0s3DQdWmmLDNX/v6nI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D5gCBgeljR+d3HTXT35mnoLVxgO5Y+Y/QJADVJLKkdlHSE1y/kiXynItyCyyRo+uE 2pJG2XLwBoPiBmz/5tUkb9fE0lyiuox/mpq5cR6/8dLz3BhP1sBVna+EPr6Aq5N73C +Aq17tlWtgM2L9nIu4HiF4u2eOBrmHcmzhQAyZrM= 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.14 155/222] hugetlbfs: dirty pages as they are added to pagecache Date: Sun, 11 Nov 2018 14:24:12 -0800 Message-Id: <20181111221701.205454832@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -3644,6 +3644,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);