From patchwork Wed Jun 15 23:34:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward Wu X-Patchwork-Id: 12883066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 338E5C433EF for ; Wed, 15 Jun 2022 23:34:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CECA6B0071; Wed, 15 Jun 2022 19:34:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 257806B0072; Wed, 15 Jun 2022 19:34:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F89C6B0074; Wed, 15 Jun 2022 19:34:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 019C26B0071 for ; Wed, 15 Jun 2022 19:34:34 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id C8FF461259 for ; Wed, 15 Jun 2022 23:34:34 +0000 (UTC) X-FDA: 79582076868.06.59DF460 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by imf23.hostedemail.com (Postfix) with ESMTP id CD644140007 for ; Wed, 15 Jun 2022 23:34:33 +0000 (UTC) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.73 with qID 25FNYRy54015276, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36504.realtek.com.tw[172.21.6.27]) by rtits2.realtek.com.tw (8.15.2/2.71/5.88) with ESMTPS id 25FNYRy54015276 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Thu, 16 Jun 2022 07:34:27 +0800 Received: from RTEXMBS03.realtek.com.tw (172.21.6.96) by RTEXH36504.realtek.com.tw (172.21.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 16 Jun 2022 07:34:26 +0800 Received: from localhost.localdomain (172.21.177.191) by RTEXMBS03.realtek.com.tw (172.21.6.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 16 Jun 2022 07:34:25 +0800 From: Edward Wu To: Andrew Morton , , CC: , , Subject: [PATCH v3] mm: cma: sync everything after EBUSY Date: Thu, 16 Jun 2022 07:34:20 +0800 Message-ID: <20220615233420.3783-1-edwardwu@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220615021504.23358-1-edwardwu@realtek.com> References: <20220615021504.23358-1-edwardwu@realtek.com> MIME-Version: 1.0 X-Originating-IP: [172.21.177.191] X-ClientProxiedBy: RTEXH36504.realtek.com.tw (172.21.6.27) To RTEXMBS03.realtek.com.tw (172.21.6.96) X-KSE-ServerInfo: RTEXMBS03.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: trusted connection X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Deterministic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 06/15/2022 23:18:00 X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: =?big5_tw?b?Q2xlYW4sIGJhc2VzOiAyMDIyLzYvMTUgpFWkyCAxMDow?= =?big5_tw?b?MTowMA==?= X-KSE-BulkMessagesFiltering-Scan-Result: protection disabled X-KSE-ServerInfo: RTEXH36504.realtek.com.tw, 9 X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: protection disabled ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655336074; a=rsa-sha256; cv=none; b=pnIrkye3XQH3jZyTumUuKZgIXdmbYufj1k5ly3128FQe+z5KopND+/i9kquxpikX5w1T27 C3ar3BzxDMJEHiXtfBU9fYG47bAukwXaxZCxAosRoaikBOVfAWT2rt3uo0iKpvVIFVey45 KtT2jfHTCRa12T0U3y+qkfXyXtgm7YE= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of edwardwu@realtek.com designates 211.75.126.72 as permitted sender) smtp.mailfrom=edwardwu@realtek.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655336074; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uUCLRY4pPPn5esHgcNDSNqxgaoYD1maOTHPGCkoz20s=; b=X3eUfpDC3zpo5nH2+P/hg0lbo95pLdRlonausXWO0ZGgNY6QOllq/PBaElfX4EBFR5C2aX p0ubmZjvpT8Iv86i/YyvsvMpCNZzUy9NVWqlMIxNIBjvxGEtexyDFQMJE227zULxq5zP9t EQXDY6O89HvHrf/p0m396d/edOpYpVk= X-Rspamd-Queue-Id: CD644140007 X-Rspam-User: Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of edwardwu@realtek.com designates 211.75.126.72 as permitted sender) smtp.mailfrom=edwardwu@realtek.com X-Rspamd-Server: rspam06 X-Stat-Signature: znc8d4dhfbmpmq6khtfyb5o4iwozr6mx X-HE-Tag: 1655336073-8 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: Since file-backed memory on CMA area could take long-term pinning. By Minchan Kim's debug commit 151e084af494 ("mm: page_alloc: dump migrate-failed pages only at -EBUSY") We know the pinned page comes from buffer_head, ext4 journal, FS metadata. Sync everything after EBUSY that can unpin most file-system pages. And raise the success rate at next time try. Link: https://lkml.kernel.org/r/20220615021504.23358-1-edwardwu@realtek.com Signed-off-by: Edward Wu --- V3: - Use non-inline prototype for work function v2: - Fix compile warning mm/cma.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index eaa4b5c920a2..ddb9f0fbec27 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "cma.h" @@ -410,6 +411,24 @@ static void cma_debug_show_areas(struct cma *cma) static inline void cma_debug_show_areas(struct cma *cma) { } #endif +static void cma_sync_work(struct work_struct *work) +{ + ksys_sync(); + kfree(work); + pr_debug("%s(): EBUSY Sync complete\n", __func__); +} + +static void cma_ebusy_sync_pinned_pages(void) +{ + struct work_struct *work; + + work = kmalloc(sizeof(*work), GFP_ATOMIC); + if (work) { + INIT_WORK(work, cma_sync_work); + schedule_work(work); + } +} + /** * cma_alloc() - allocate pages from contiguous area * @cma: Contiguous memory region for which the allocation is performed. @@ -430,6 +449,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, unsigned long i; struct page *page = NULL; int ret = -ENOMEM; + bool sys_synchronized = false; if (!cma || !cma->count || !cma->bitmap) goto out; @@ -480,6 +500,11 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, if (ret != -EBUSY) break; + if (!sys_synchronized) { + sys_synchronized = true; + cma_ebusy_sync_pinned_pages(); + } + pr_debug("%s(): memory range at %p is busy, retrying\n", __func__, pfn_to_page(pfn));