From patchwork Wed Oct 30 20:07:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11220013 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C2AAF13B1 for ; Wed, 30 Oct 2019 20:08:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8B5922080F for ; Wed, 30 Oct 2019 20:08:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="QgQgzVHo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B5922080F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=fb.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A59256B0005; Wed, 30 Oct 2019 16:08:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A0BB46B0007; Wed, 30 Oct 2019 16:08:12 -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 8F8ED6B0008; Wed, 30 Oct 2019 16:08:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id 6B7B56B0005 for ; Wed, 30 Oct 2019 16:08:12 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id F2A7D180AD83B for ; Wed, 30 Oct 2019 20:08:11 +0000 (UTC) X-FDA: 76101537582.12.thing23_d4b212969d56 X-Spam-Summary: 2,0,0,4b6062ae0b22a7da,d41d8cd98f00b204,prvs=62064ef8f2=songliubraving@fb.com,::kernel-team@fb.com:songliubraving@fb.com:kirill.shutemov@linux.intel.com:hughd@google.com:william.kucharski@oracle.com:hannes@cmpxchg.org:akpm@linux-foundation.org:willy@infradead.org,RULES_HIT:41:355:379:541:800:960:973:988:989:1260:1261:1277:1313:1314:1345:1431:1437:1516:1518:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:5007:6261:6653:8660:8957:10004:10400:10450:10455:11026:11473:11658:11914:12043:12291:12296:12297:12438:12555:12895:13148:13184:13221:13229:13230:14096:14097:14181:14394:14721:19904:19999:21080:21433:21451:21627:21740:30054:30064,0,RBL:67.231.145.42:@fb.com:.lbl8.mailshell.net-62.2.0.100 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:31,LUA_SUMMARY:none X-HE-Tag: thing23_d4b212969d56 X-Filterd-Recvd-Size: 4852 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 30 Oct 2019 20:08:11 +0000 (UTC) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x9UK86Ff013625 for ; Wed, 30 Oct 2019 13:08:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=68L6JT6et2wxQ19L/wk8Vl6nd1tNpVw3YNeSUimTUXs=; b=QgQgzVHorLuTPYZ0W88zujavwpMCibDBuE2HKScnJVR9ZT1RmCGjBNsmGUbVDJMU6tk5 Wrs0KXmNZqXPQRqql108Uv2YMgV3qKY4gYKGbTMIcROLF+9uv2r2Ejngc79TCgsZ+X6m bKtqWYP3U2W7Y2g76sSsNRLxScVbpTN+M54= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2vybre9yra-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 30 Oct 2019 13:08:09 -0700 Received: from 2401:db00:2120:80d4:face:0:39:0 (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1713.5; Wed, 30 Oct 2019 13:07:39 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 625A662E1D52; Wed, 30 Oct 2019 13:07:37 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: CC: , Song Liu , "Kirill A . Shutemov" , Hugh Dickins , William Kucharski , Johannes Weiner , Andrew Morton , Matthew Wilcox Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH] mm/thp: flush file for !is_shmem PageDirty() case in collapse_file() Date: Wed, 30 Oct 2019 13:07:36 -0700 Message-ID: <20191030200736.3455046-1-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-10-30_08:2019-10-30,2019-10-30 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxlogscore=955 spamscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 suspectscore=1 mlxscore=0 impostorscore=0 malwarescore=0 adultscore=0 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1908290000 definitions=main-1910300175 X-FB-Internal: deliver 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: For non-shmem file THPs, khugepaged only collapses read only .text mapping (VM_DENYWRITE). These pages should not be dirty except the case where the file hasn't been flushed since first write. Call filemap_flush() in collapse_file() to accelerate the write back in such cases. Also add warning if PageDirty() triggered for pages from readahead path. Reported-and-tested-by: syzbot+efb9e48b9fbdc49bb34a@syzkaller.appspotmail.com Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: William Kucharski Cc: Johannes Weiner Cc: Andrew Morton Cc: Matthew Wilcox Signed-off-by: Song Liu Signed-off-by: Song Liu Acked-by: Johannes Weiner Signed-off-by: Andrew Morton Reported-by: syzbot+efb9e48b9fbdc49bb34a@syzkaller.appspotmail.com Signed-off-by: Song Liu Signed-off-by: Song Liu --- mm/khugepaged.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 3ec5333ae94d..d61368b8251e 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1601,6 +1601,33 @@ static void collapse_file(struct mm_struct *mm, result = SCAN_FAIL; goto xa_unlocked; } + if (WARN_ON_ONCE(PageDirty(page))) { + /* + * page from readahead should not + * be dirty. Show warning if this + * somehow happens. + */ + result = SCAN_FAIL; + goto out_unlock; + } + } else if (PageDirty(page)) { + /* + * khugepaged only works on read-only fd, + * so this page is dirty because it hasn't + * been flushed since first write. There + * won't be new dirty pages. + * + * Trigger async flush here and hope the + * writeback is done when khugepaged + * revisits this page. + * + * This is a one-off situation. We are not + * forcing writeback in loop. + */ + xas_unlock_irq(&xas); + filemap_flush(mapping); + result = SCAN_FAIL; + goto xa_unlocked; } else if (trylock_page(page)) { get_page(page); xas_unlock_irq(&xas);