From patchwork Fri Apr 9 07:17:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 12193205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36D81C43462 for ; Fri, 9 Apr 2021 07:17:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 93C1D61177 for ; Fri, 9 Apr 2021 07:17:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93C1D61177 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 185146B006E; Fri, 9 Apr 2021 03:17:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 10C286B0070; Fri, 9 Apr 2021 03:17:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D92C36B0071; Fri, 9 Apr 2021 03:17:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0162.hostedemail.com [216.40.44.162]) by kanga.kvack.org (Postfix) with ESMTP id B75156B006E for ; Fri, 9 Apr 2021 03:17:30 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7CED71830EE7D for ; Fri, 9 Apr 2021 07:17:30 +0000 (UTC) X-FDA: 78011973060.09.7D6BC3F Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by imf23.hostedemail.com (Postfix) with ESMTP id CBB17A0003A0 for ; Fri, 9 Apr 2021 07:17:28 +0000 (UTC) Received: by mail-ej1-f52.google.com with SMTP id u17so7065005ejk.2 for ; Fri, 09 Apr 2021 00:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MAgKFkUbajfTwkiBbjHCwLbY8LqpQ8PBmh7VA/cwU0E=; b=igEspD4oLTpM4o2jCwSGcYwjzgvaFDiBYrZde/yigoCOzASZ6Q36kFdOLTPk9+sEKA At9Rg6okYKLJenOHCVlutmLzuLAhyDZfgGBYJ66Oj8C6MPsS8wita034AoWkMFIgC25Z 7hsoj7iGl8V5wzeL/wT3tqHTfrZTHkZwk5UBViKyHTywBmZFq0frm8mI3J2xlddZBmoE s8q8GSI2WepiZ10MAzwDGwDMtYCoPpkyTnDhEtIa1GyGDEw6k37Rs+HJ9yff6WL6sw1O 4WqcJX+pPtmQilHkwSI8hffyk+1BcLWllcyd2nRmfoTOw/Abay7/0UE6y0hP+L+s4Qlb YxuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=MAgKFkUbajfTwkiBbjHCwLbY8LqpQ8PBmh7VA/cwU0E=; b=AArSiaZ9geZ0P7m9kkRJNNw1gGNjbEGbAP6EDXtoiGRcCuymWOSCcAOe0cGknmgvpH xTyrq78R9V4js1Jg3g07iyAyf9TJC0fknsDIuWlaHUSdXW8g/IYPF8aAEhoygGPhBynn 3wkgNaeF1PlpD7FjYjvyFc0BaLh5nralz1uB5rHPIh77Mzz3lB7trz8Sb9ih79AmeGZA Nmq9LeXkGAi2L9eAXJMiBDeyzyQiL3YUSRCgRVBmzSoUxWhNtRsIsQLSGuyCV9P7bt5o FDC9fhqYprazNUpHMKKm/N8etW6xMHxl73TuUY+W+XlYu3Bx3wOlBz84ZfzP6VMUOUIm FKow== X-Gm-Message-State: AOAM532RsZaR9tTRvB/Dk/xJQXlB2Fw5BVborsmmr5JNqtYJJKrWlPyj 3jmxSsgnmpWBpiBU1m8AGew= X-Google-Smtp-Source: ABdhPJzQ2tCFOmAsi20Gal6ccZzgbiWTy3xs28H9Fe7zY+J/NCEjtr1WZzzVEoA6J7yNPFrn15rtkw== X-Received: by 2002:a17:906:5618:: with SMTP id f24mr15226911ejq.414.1617952646960; Fri, 09 Apr 2021 00:17:26 -0700 (PDT) Received: from abel.fritz.box ([2a02:908:1252:fb60:216f:9340:7a2b:4f98]) by smtp.gmail.com with ESMTPSA id w1sm905369edt.89.2021.04.09.00.17.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 00:17:26 -0700 (PDT) From: " =?utf-8?q?Christian_K=C3=B6nig?= " X-Google-Original-From: =?utf-8?q?Christian_K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: ray.huang@amd.com, daniel@ffwll.ch, akpm@linux-foundation.org Subject: [PATCH 1/2] mm/vmscan: add sync_shrinkers function Date: Fri, 9 Apr 2021 09:17:24 +0200 Message-Id: <20210409071725.1532-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Stat-Signature: nbrd87m734d5o8gqz45sm45s3tzwcj5r X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CBB17A0003A0 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=mail-ej1-f52.google.com; client-ip=209.85.218.52 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617952648-268764 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: To be able to switch to a spinlock and reduce lock contention in the TTM shrinker we don't want to hold a mutex while unmapping and freeing pages from the pool. But then we somehow need to prevent a race between (for example) the shrinker trying to free pages and hotplug trying to remove the device which those pages belong to. Taking and releasing the shrinker semaphore on the write side after unmapping and freeing all pages should make sure that no shrinker is running in paralell any more. Signed-off-by: Christian König --- include/linux/shrinker.h | 1 + mm/vmscan.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/linux/shrinker.h b/include/linux/shrinker.h index 0f80123650e2..6b75dc372fce 100644 --- a/include/linux/shrinker.h +++ b/include/linux/shrinker.h @@ -92,4 +92,5 @@ extern void register_shrinker_prepared(struct shrinker *shrinker); extern int register_shrinker(struct shrinker *shrinker); extern void unregister_shrinker(struct shrinker *shrinker); extern void free_prealloced_shrinker(struct shrinker *shrinker); +extern void sync_shrinkers(void); #endif diff --git a/mm/vmscan.c b/mm/vmscan.c index 562e87cbd7a1..46cd9c215d73 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -408,6 +408,16 @@ void unregister_shrinker(struct shrinker *shrinker) } EXPORT_SYMBOL(unregister_shrinker); +/** + * sync_shrinker - Wait for all running shrinkers to complete. + */ +void sync_shrinkers(void) +{ + down_write(&shrinker_rwsem); + up_write(&shrinker_rwsem); +} +EXPORT_SYMBOL(sync_shrinkers); + #define SHRINK_BATCH 128 static unsigned long do_shrink_slab(struct shrink_control *shrinkctl,