Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp80229iog; Tue, 14 Jun 2022 19:45:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCXk7DoeJxwkDBOj05GFkvFLHzeus/97KuSDJvWEyOUcTEot6bpC3IUyj5Ug8PctXE20+7 X-Received: by 2002:a17:902:f815:b0:163:c524:e475 with SMTP id ix21-20020a170902f81500b00163c524e475mr7314335plb.37.1655261130784; Tue, 14 Jun 2022 19:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655261130; cv=none; d=google.com; s=arc-20160816; b=MWGO1qx2ya3sbUGe3S+hrzJCx4kfxFbfPbflO5p+Lv5oR/ZF5pBFoNwlkQeTmG0iVz MOg5g+04wcURtVnCMre6cm4C9YKaIL4KCYEfJcgEpZiKWIZDqPanOdNxzzJdwq7SmOUv ortl8qHMqBVkoEGFkYwapYlAsLxz323OheUaWBbuLPBlMXPsRmRvKrGJLpqvzztBHA1h QEiawvzHk8liGu60XzC1hWOzQXb/3DUSVCRCl9Vp9sm90Vg72aYRtWYmq3lrh5+9t5mE BRDw6hF1d6eAdLh04gzc9tJAUmVlxqKm4DrGTcum04edfoMRg7jlbOoMQIcqgZJsIBFb wJlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :authenticated-by; bh=9KZhD3GYOMo/SSnVOa/4CjU/TDqiXq+8Pmdcd5Hb05A=; b=DWHhSMyTrpMplFqZuA8LxsYLsKE1cy3uu8g90i85H+GJePHP+v3RTPG7qzfPprGENU Tc9c+VLYGQ3Asnm+R/L2pZILC4SID5mK9XckhRB74T/Swzdhe5DEpSPkntgU8icN1wti WPFmj4+zl3WnIYEg/jX5DyhyeSOW2euV43m04F6vOYhmkYCV29n5RyeefRHy0iuVH9F6 ysqsv4l6bCUjjNuWWkOCkQliewfG8oPQyuyQoAg7m5gaGy7Bc4OAvqAVfNEmwO8iPSFP JY1IeWwPZMBaRKTz4yKo1mUoEKBbcD4/wcWUYF54fnSkvXuPOxyVsSmX0AWHOOro4/qZ e6jA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h18-20020a170902f55200b00161cc059dfdsi19604456plf.298.2022.06.14.19.45.17; Tue, 14 Jun 2022 19:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239671AbiFOCPx (ORCPT + 99 others); Tue, 14 Jun 2022 22:15:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229924AbiFOCPv (ORCPT ); Tue, 14 Jun 2022 22:15:51 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D966748E6F for ; Tue, 14 Jun 2022 19:15:41 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.73 with qID 25F2FBDr8007761, 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 25F2FBDr8007761 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 15 Jun 2022 10:15:11 +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; Wed, 15 Jun 2022 10:15:11 +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; Wed, 15 Jun 2022 10:15:11 +0800 From: Edward Wu To: Andrew Morton , , CC: , , Subject: [PATCH] mm: cma: sync everything after EBUSY Date: Wed, 15 Jun 2022 10:15:04 +0800 Message-ID: <20220615021504.23358-1-edwardwu@realtek.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain 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 01:58:00 X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: =?big5?B?Q2xlYW4sIGJhc2VzOiAyMDIyLzYvMTQgpFWkyCAxMDowMDowMA==?= 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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,T_SCC_BODY_TEXT_LINE, T_SPF_HELO_TEMPERROR,T_SPF_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Edward Wu --- mm/cma.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/mm/cma.c b/mm/cma.c index eaa4b5c920a2..eefd725064e1 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 +void cma_sync_work(struct work_struct *work) +{ + ksys_sync(); + kfree(work); + pr_debug("%s(): EBUSY Sync complete\n", __func__); +} + +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)); -- 2.17.1