From mboxrd@z Thu Jan 1 00:00:00 1970 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 6D99BC33CB6 for ; Thu, 16 Jan 2020 14:44:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 447652176D for ; Thu, 16 Jan 2020 14:44:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579185888; bh=sSD5mwamux5+wjoulyCcRI5d07g/ay7zhN0fXj2xIns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=vDVLxtErn5+K5D8bpKs9qmPHlxmJDUtuYNw3SgzIfLCsDQ0AkQ1T6UIttrmYHJmRO ke8Jzys5TkJWTuoF6xkdICXxu/vivwLZTBjqjXGBI4yLVo16nMDcBCOUWiRy/vo3tz TV3hvqbt/q4QbXPJ6FLUzM4bcL/DJKTJ1t6oPqys= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727022AbgAPOor (ORCPT ); Thu, 16 Jan 2020 09:44:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:35298 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726366AbgAPOor (ORCPT ); Thu, 16 Jan 2020 09:44:47 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4ED7820684; Thu, 16 Jan 2020 14:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579185886; bh=sSD5mwamux5+wjoulyCcRI5d07g/ay7zhN0fXj2xIns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J65etQUtUrdHX10B9ewczQfWBBgoADBQmeyjR5eze8xxlMl0CZHLJxFLB4yPpknGX psUNAWTfyfAv52AgOaoGYTW3W3NcCmP8B1S9JdyVrvdk/dVbH5kKKS2AGSCY6byePP o7XOUgnjfwwwVbbHPBW7a0aSvcSUM/ANDfBONOrA= From: Masami Hiramatsu To: Brendan Gregg , Steven Rostedt , Alexei Starovoitov Cc: mhiramat@kernel.org, Ingo Molnar , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Borkmann , Arnaldo Carvalho de Melo , "David S . Miller" , paulmck@kernel.org, joel@joelfernandes.org, "Naveen N . Rao" , Anil S Keshavamurthy Subject: [RFT PATCH 03/13] kprobes: Postpone optimizer until a bunch of probes (un)registered Date: Thu, 16 Jan 2020 23:44:42 +0900 Message-Id: <157918588172.29301.12636373067838941611.stgit@devnote2> X-Mailer: git-send-email 2.20.1 In-Reply-To: <157918584866.29301.6941815715391411338.stgit@devnote2> References: <157918584866.29301.6941815715391411338.stgit@devnote2> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a counter to kick_kprobe_optimizer() to detect any additional register/unregister kprobes and postpone kprobe_optimizer() until a bunch of probes are registered. This might improve some long waiting unregistration process for bunch of kprobes. Signed-off-by: Masami Hiramatsu --- kernel/kprobes.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index a2c755e79be7..0dacdcecc90f 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -465,6 +465,7 @@ static struct kprobe *get_optimized_kprobe(unsigned long addr) static LIST_HEAD(optimizing_list); static LIST_HEAD(unoptimizing_list); static LIST_HEAD(freeing_list); +static int kprobe_optimizer_queue_update; static void kprobe_optimizer(struct work_struct *work); static DECLARE_DELAYED_WORK(optimizing_work, kprobe_optimizer); @@ -555,12 +556,22 @@ static void do_free_cleaned_kprobes(void) static void kick_kprobe_optimizer(void) { schedule_delayed_work(&optimizing_work, OPTIMIZE_DELAY); + kprobe_optimizer_queue_update++; } /* Kprobe jump optimizer */ static void kprobe_optimizer(struct work_struct *work) { mutex_lock(&kprobe_mutex); + + /* + * If new kprobe is queued in optimized/unoptimized list while + * OPTIMIZE_DELAY waiting period, wait again for a series of + * probes registration/unregistrations. + */ + if (kprobe_optimizer_queue_update > 1) + goto end; + cpus_read_lock(); mutex_lock(&text_mutex); /* Lock modules while optimizing kprobes */ @@ -593,6 +604,8 @@ static void kprobe_optimizer(struct work_struct *work) mutex_unlock(&text_mutex); cpus_read_unlock(); +end: + kprobe_optimizer_queue_update = 0; /* Step 5: Kick optimizer again if needed */ if (!list_empty(&optimizing_list) || !list_empty(&unoptimizing_list)) kick_kprobe_optimizer();