From patchwork Mon Sep 11 09:44:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379057 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 F4119EE7FF4 for ; Mon, 11 Sep 2023 09:45:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7AFEA6B019C; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 760B36B019D; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6293B6B019E; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 4F0846B019C for ; Mon, 11 Sep 2023 05:45:37 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 25DEB12097A for ; Mon, 11 Sep 2023 09:45:37 +0000 (UTC) X-FDA: 81223834314.14.5725C4D Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf25.hostedemail.com (Postfix) with ESMTP id 1483CA001C for ; Mon, 11 Sep 2023 09:45:34 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GXFX1PNx; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425535; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oUoMNQAb0HDNERTf3y3lU6vkCLiBk8akZS8yI7+n5rc=; b=qsgnXq3Qxig2mCCqAfSjL6sL78IbAs2fhdtCYtktAf3rtql/DZilHTFJFqR/xTH4+ljsl8 D+WW+d7phskUizi6AEGtimZuO3hylu/U6mioKpmXGRZqH60WMedt9QP+16ssIxmpEvbm31 mTC1seJla/e0SU0XNAGrBwQOIK6c61k= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=GXFX1PNx; spf=pass (imf25.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425535; a=rsa-sha256; cv=none; b=GA0M/kix9S2WvQBYXBH0NiQA6u5mGcs5JiDwCuCMTpgVkJOPFhQGboSSPf1BG4mXLyEqTq dB4ATKVZUCLwrZgUM5fNft3BfOPON4GJyn/neRDy7kem1nIVH1mQiQRGmqTXZ3NCp+E9jM 1+Dp9p7rYwojoLIRbUhP0WmC1N52Vpg= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-68cc1b70e05so1080979b3a.1 for ; Mon, 11 Sep 2023 02:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425534; x=1695030334; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oUoMNQAb0HDNERTf3y3lU6vkCLiBk8akZS8yI7+n5rc=; b=GXFX1PNxTENCQ/IiNsCn3MZe2Y2SOh6ZjQtuH03JQVGgiZRZu8pIhQnD86Q9/o9CoU JyOmHYowFEW3nPVX2ATbHwgUNaRIw4wrhIYTPZVx8/9N8OdxCK+/2eaNbPOFU1RQv9bR 0y0J7Zuim26hSTUpJfQu+HbB7Hc6qkh8zNWdEyBPXng7pu0K9e3fR9UUAQwsAPIuT8Ba EIBj0iia+JYuqa+bo/zscBDFeQgYQHyRHAviWt43KF2XW0sVWM8yFHvwdJ3IpTnKj6+8 K3oujT/rfO8fV+PfVugXyrZ0FBwdVIWjMepN6lQXXpJEZFcWcKnePHY3tTItHqiHsKgV RBPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425534; x=1695030334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oUoMNQAb0HDNERTf3y3lU6vkCLiBk8akZS8yI7+n5rc=; b=DKvACvFBgD7CYE0obDYczp9RbdtnFtuU+WPjzDyi3u50JHSAjwPtw523y5aCwMZSxl dfEVmTv82NSM+DBxnSWNuKzBVsMZYUYX1bLV6mvJUke3tPZJqfTCRfDMNqEDmBCqAxlM IkXkTXkRYCHaHtEMiMIwH2fimcuAjDhT5i84vYoUeTig7CzgFn/EdyN+QV58+QJbrl8G ikic9AXFrXAJy7iX0HnwahP+1LqI7+UrXsW2GSCzQMZagIJ5jPTl9w+9FKfWXptkcB4K s0TV8SR3WP7ifbxQ2Cg5kl6fGU7e4/bFiZxjajloV/rtiOTrDblIqp6ExOcm6PnpIxm1 j0UA== X-Gm-Message-State: AOJu0Yzy+c16GfIQRUhHEcFVIyAZ5+H4xhul+1FjtLYDCO9N4M5B6Y1Q ieCBab0jRUUHjBibB3W1JVcBJQ== X-Google-Smtp-Source: AGHT+IFTLTKyDsfu1NylfkAEUjAx8ahS4NnLvg9xanza3vKrJB8S7jYrE7HTHnlVMC2Ur/FZ9D9EPw== X-Received: by 2002:a05:6a20:394c:b0:13d:7aa3:aa6c with SMTP id r12-20020a056a20394c00b0013d7aa3aa6cmr9989617pzg.0.1694425533979; Mon, 11 Sep 2023 02:45:33 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.45.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:45:33 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Carlos Llamas Subject: [PATCH v6 03/45] binder: dynamically allocate the android-binder shrinker Date: Mon, 11 Sep 2023 17:44:02 +0800 Message-Id: <20230911094444.68966-4-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1483CA001C X-Rspam-User: X-Stat-Signature: ad9oeypgnqjt887fytbyc9o4bqf4qc56 X-Rspamd-Server: rspam01 X-HE-Tag: 1694425534-292662 X-HE-Meta: U2FsdGVkX18TELv5l3Yxz41sv4P+40aT8BE7wvRVYtwmnVDBYrY6CsGjZkEvOEywBIuxHT08KUW9LvgujRg9fJvTXrbgDnHZvv6DWfFvNPYQEXGsze0xa81dvhB2qRBMNhstWmZJ2cCJRk53/8aAPRmVVoqftvXjlOGk1Kdqk/x4/ODmR4svWiUddYKkv4BIRsV/E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Opj49ZArtVmuVkcAmnOoD+mbNwF6LPEac4j2iZMrAuHjic5CEDdClSVPVB9iX+CpVk4m5SANU/YaqxIPD6FxdUrgxu9dz777JK0XNrQ2TIovIEX6rI9lktxvaXM4st7tbGfecgrzh1TKQftuNhBhPI19QjzFBKJYQa69S0XT3PH3LnUK3lXuTWPvJDR7iWcAfMKHnMj7922GA== 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: Use new APIs to dynamically allocate the android-binder shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: Carlos Llamas CC: Greg Kroah-Hartman --- drivers/android/binder_alloc.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c index e3db8297095a..138f6d43d13b 100644 --- a/drivers/android/binder_alloc.c +++ b/drivers/android/binder_alloc.c @@ -1053,11 +1053,7 @@ binder_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) NULL, sc->nr_to_scan); } -static struct shrinker binder_shrinker = { - .count_objects = binder_shrink_count, - .scan_objects = binder_shrink_scan, - .seeks = DEFAULT_SEEKS, -}; +static struct shrinker *binder_shrinker; /** * binder_alloc_init() - called by binder_open() for per-proc initialization @@ -1077,19 +1073,29 @@ void binder_alloc_init(struct binder_alloc *alloc) int binder_alloc_shrinker_init(void) { - int ret = list_lru_init(&binder_alloc_lru); + int ret; - if (ret == 0) { - ret = register_shrinker(&binder_shrinker, "android-binder"); - if (ret) - list_lru_destroy(&binder_alloc_lru); + ret = list_lru_init(&binder_alloc_lru); + if (ret) + return ret; + + binder_shrinker = shrinker_alloc(0, "android-binder"); + if (!binder_shrinker) { + list_lru_destroy(&binder_alloc_lru); + return -ENOMEM; } - return ret; + + binder_shrinker->count_objects = binder_shrink_count; + binder_shrinker->scan_objects = binder_shrink_scan; + + shrinker_register(binder_shrinker); + + return 0; } void binder_alloc_shrinker_exit(void) { - unregister_shrinker(&binder_shrinker); + shrinker_free(binder_shrinker); list_lru_destroy(&binder_alloc_lru); }