From patchwork Wed Nov 6 06:09:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11229363 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 A6CE71515 for ; Wed, 6 Nov 2019 06:12:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F9942178F for ; Wed, 6 Nov 2019 06:12:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="nbZZHlW7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F9942178F 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 B7ED06B0006; Wed, 6 Nov 2019 01:12:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B2F516B000A; Wed, 6 Nov 2019 01:12:07 -0500 (EST) 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 A1D136B000E; Wed, 6 Nov 2019 01:12:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 8E7686B0006 for ; Wed, 6 Nov 2019 01:12:07 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 3A250180AD802 for ; Wed, 6 Nov 2019 06:12:07 +0000 (UTC) X-FDA: 76124832294.07.beast10_69c3e74165527 X-Spam-Summary: 2,0,0,3063f81b826621f7,d41d8cd98f00b204,prvs=6213cc43f4=songliubraving@fb.com,:linux-kernel@vger.kernel.org::akpm@linux-foundation.org:matthew.wilcox@oracle.com:kernel-team@fb.com:william.kucharski@oracle.com:kirill.shutemov@linux.intel.com:songliubraving@fb.com:hughd@google.com:hannes@cmpxchg.org:willy@infradead.org,RULES_HIT:41:355:379:541:800:960:967:973:988:989:1260:1261:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1711:1730:1747:1777:1792:2393:2525:2559:2563:2682:2685:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:5007:6261:6653:8660:8957:9025:10004:10400:10450:10455:11026:11658:11914:12043:12296:12297:12555:12895:12986:13069:13148:13184:13229:13230:13255:13311:13357:14096:14097:14181:14394:14721:19904:19999:21080:21433:21451:21627:21740:21749:21811:30054:30064,0,RBL:error,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCac he:0,MSF X-HE-Tag: beast10_69c3e74165527 X-Filterd-Recvd-Size: 4773 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Wed, 6 Nov 2019 06:12:06 +0000 (UTC) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xA6681PS027038 for ; Tue, 5 Nov 2019 22:12:03 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=XlCuU5N/+fFIuKLh8fAov4sp+sZHEolANP8THw5ikpA=; b=nbZZHlW7kHx3YCrWxC5lC2zbb7cYvB8sYsza7H5x59KgC1HKe/W3SHipEwyHl3KgjXgi CkUUKxaI5AxDmUzrCxKz/gh00OpxLQomiTLv9MPI7lvl+Tg5LAWO/zoaH70MxJRuCNtp lVNcpJ+Zrke0MJ+cbPkRSH8eQ8JsJ4iEEDo= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 2w3fhxjhph-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 05 Nov 2019 22:12:03 -0800 Received: from 2401:db00:2120:81ca:face:0:31:0 (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Tue, 5 Nov 2019 22:12:02 -0800 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 3348962E36EB; Tue, 5 Nov 2019 22:09:55 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig006.ftw2.facebook.com To: , , CC: , , , , Song Liu , Hugh Dickins , Johannes Weiner , Matthew Wilcox Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH v5 2/2] mm/thp: flush file for !is_shmem PageDirty() case in collapse_file() Date: Tue, 5 Nov 2019 22:09:30 -0800 Message-ID: <20191106060930.2571389-3-songliubraving@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191106060930.2571389-1-songliubraving@fb.com> References: <20191106060930.2571389-1-songliubraving@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-11-06_01:2019-11-05,2019-11-06 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 mlxlogscore=934 clxscore=1015 phishscore=0 malwarescore=0 spamscore=0 lowpriorityscore=0 priorityscore=1501 adultscore=0 suspectscore=0 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1908290000 definitions=main-1911060064 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. Cc: Kirill A. Shutemov Cc: Hugh Dickins Cc: William Kucharski Cc: Johannes Weiner Cc: Andrew Morton Cc: Matthew Wilcox Signed-off-by: Song Liu --- [songliubraving@fb.com: flush file for !is_shmem PageDirty() case in collapse_file()] https://lkml.kernel.org/linux-mm/20191030200736.3455046-1-songliubraving@fb.com/ --- mm/khugepaged.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) -- 2.17.1 diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 40215795d641..513cce897794 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1601,6 +1601,24 @@ static void collapse_file(struct mm_struct *mm, result = SCAN_FAIL; goto xa_unlocked; } + } 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);