From patchwork Thu Oct 18 04:10:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Kravetz X-Patchwork-Id: 10646693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BEF1109C for ; Thu, 18 Oct 2018 04:11:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5550028B0D for ; Thu, 18 Oct 2018 04:11:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4920C28AB0; Thu, 18 Oct 2018 04:11:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC8BC28B00 for ; Thu, 18 Oct 2018 04:10:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2FC666B0003; Thu, 18 Oct 2018 00:10:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2ABB66B0005; Thu, 18 Oct 2018 00:10:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 174756B0007; Thu, 18 Oct 2018 00:10:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by kanga.kvack.org (Postfix) with ESMTP id E07A16B0003 for ; Thu, 18 Oct 2018 00:10:53 -0400 (EDT) Received: by mail-io1-f72.google.com with SMTP id n10-v6so15708470iog.5 for ; Wed, 17 Oct 2018 21:10:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=WpKJOt13oO9GdKIzUCUIf6uwwSO11fcDUAucu7TQbn8=; b=ptKoDkm6gMlmq+faUbaDXC83Af8aSBajZ06eZ/7MHMRoOQzC7gIArPMsuwFsdYqMaS n4+fzMyZpyGGS7KpmY0FGA7q4YBHUL+ft273rgwa7xacPhIvnserbuZZlt8WmDAHu7BL WjbwzP/AvmA7MEQWCj5vT3GbLHLfCIlHwn/3ytdBpOla11kkbMxIKcRoo+dFdouraIt0 QUWk4OxBzR3dpXhJTISlyhlvdNa+KiHnhyiibQvGmaPVW7gT9wJZ1MmX62yf1JNj1gF+ lhfRBfkQuuJAqnBEIrGU6TQjizBAJ0gn8pjoE85UCq8Ub8W61SzSaXGoHTNYYouUUNjU YdCw== X-Gm-Message-State: ABuFfoifJ/9YP4a3a3+i06NF4N0FpRNIDAQjeQWUvZequnGo9fuNG4Vm l+WeiQYhnu4OeDmp1NEkmrlsQUR+Nw4LnCTl/ThWStKNAyV2T/5JR6eqt0si0GVLuRvTk3PgoSK XiqLo36z605fBU1AdVvBLnDQIVH4s1iqWGfjmKAi29NvbYt7MZofh/nla5tUnsZ9QFg== X-Received: by 2002:a5e:c117:: with SMTP id v23-v6mr20369365iol.155.1539835853529; Wed, 17 Oct 2018 21:10:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV637YY7QAMppRi0MaACwyW3H6koI5yU/0X5ag5UlO4ANF0VgccZDshtRQza7PJm0waQPNhVe X-Received: by 2002:a5e:c117:: with SMTP id v23-v6mr20369342iol.155.1539835852722; Wed, 17 Oct 2018 21:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539835852; cv=none; d=google.com; s=arc-20160816; b=ttzlnPL7k3cKD4bwgkJLUjXto65PvlZmI1DHqueLhFic+pV+m/O44ktpncHuml6+rg GECW+ogQtYQQJU3iWLBCx6479Kfss3dvS713Ixb7GVN9M4xq5uAP6yDemyk/F7/4UTUQ idllOWpaTmvLXGaB4xPG2rbew8914G3wIR6YInYT2kLksNwZn0VDJXYm7dGZPC2hMMSy W3D1luY5kSJx5x74CeJIYU+DdTv9zbDlBVajiQwd30cClO2/Cn1PpHjZDOQVhGaUrzC5 e2SQ8c4vmaP0thwpxAxSttjDL+/QTWuhWK6dgt3bqxyZUQZjZaud3fn1z4n1Bhu8K3ds Qxlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=WpKJOt13oO9GdKIzUCUIf6uwwSO11fcDUAucu7TQbn8=; b=vJ7TYbHFERURWItyZkA28HbVIpozq3DYlVWeRabAYIS9CrBRVpEVGPfvJLh+klFSky tVaNI3i4JcG8g+H7+I4cec5tZ/YfCj0lj39+t/LNsB1ot0axDLq7QyTbdMJsPRhjc7Wb 4V0knoJVUaalHhdPVnwSkgWABiz8sFT6S3+xHIEjgCvICZp5YZ401a/Wvi3R/seipOn3 v9e07lZzFfssqLvavMFVSlhdV9RCkBhGOJ9WFl93DU7V9fDuKFgzZiuVcymTRNwKt2pQ naaiwlhg52ZSXRFyunRjzk7dfhm2LqFCdA1nfgysY/PkBDfbGp8mdDE7XFgQwXdnAkBB mq/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ip7EG25U; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id t200-v6si3117321itc.56.2018.10.17.21.10.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 21:10:52 -0700 (PDT) Received-SPF: pass (google.com: domain of mike.kravetz@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ip7EG25U; spf=pass (google.com: domain of mike.kravetz@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=mike.kravetz@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9I49T9c191320; Thu, 18 Oct 2018 04:10:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=WpKJOt13oO9GdKIzUCUIf6uwwSO11fcDUAucu7TQbn8=; b=ip7EG25U+bema+gMV9ouIM33PZYbRf8ug/q37zPByT8HoChr5e2HOqbJfYC4Ts7s88HP 50OjY6FQdpiGxphJuy3KcmEznWRO4i++xAN6/k7ECgPYJ6ECYkhSDJGLIslysmdLlEI1 ZuE62PS9/DducgK9HkVQ+oT+4RFyoh+Klk7IYjLAKCvJiAe/AQhfrknv7BqVWtP+6hqS UwJzlDS+B9/FuhU5tSAdMDqvQJSvDCAZ9X7+aSo1mY8MDdlbGekCe0mDZJhXev1CRd2m IZKYXZXOZT1nbT28j2s0IkdcSyDJ78GCx24ZtIW/p6BHjHZAVE462OFWWxImMDk06Cc+ oA== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2n384ucava-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Oct 2018 04:10:45 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9I4AhEW026865 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Oct 2018 04:10:44 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w9I4Ag0l028441; Thu, 18 Oct 2018 04:10:42 GMT Received: from monkey.oracle.com (/50.38.38.67) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 17 Oct 2018 21:10:42 -0700 From: Mike Kravetz To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Michal Hocko , Hugh Dickins , Naoya Horiguchi , "Aneesh Kumar K . V" , Andrea Arcangeli , "Kirill A . Shutemov" , Davidlohr Bueso , Alexander Viro , Mike Kravetz , stable@vger.kernel.org Subject: [PATCH] hugetlbfs: dirty pages as they are added to pagecache Date: Wed, 17 Oct 2018 21:10:22 -0700 Message-Id: <20181018041022.4529-1-mike.kravetz@oracle.com> X-Mailer: git-send-email 2.17.2 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9049 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=909 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810180039 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. In addition, it makes little sense to even try to drop hugetlbfs pagecache pages, so disable calls to these filesystems in drop_caches code. Fixes: 70c3547e36f5 ("hugetlbfs: add hugetlbfs_fallocate()") Cc: stable@vger.kernel.org Signed-off-by: Mike Kravetz Acked-by: Michal Hocko to the set_page_dirty dirty Signed-off-by: Mike Kravetz Acked-by: Mihcla Hocko Reviewed-by: Khalid Aziz --- fs/drop_caches.c | 7 +++++++ mm/hugetlb.c | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/fs/drop_caches.c b/fs/drop_caches.c index 82377017130f..b72c5bc502a8 100644 --- a/fs/drop_caches.c +++ b/fs/drop_caches.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "internal.h" /* A global variable is a bit ugly, but it keeps the code simple */ @@ -18,6 +19,12 @@ static void drop_pagecache_sb(struct super_block *sb, void *unused) { struct inode *inode, *toput_inode = NULL; + /* + * It makes no sense to try and drop hugetlbfs page cache pages. + */ + if (sb->s_magic == HUGETLBFS_MAGIC) + return; + spin_lock(&sb->s_inode_list_lock); list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { spin_lock(&inode->i_lock); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 5c390f5a5207..7b5c0ad9a6bd 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3690,6 +3690,12 @@ int huge_add_to_page_cache(struct page *page, struct address_space *mapping, 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);