From patchwork Thu Jan 3 16:09:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Ivanov X-Patchwork-Id: 1020379 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cambridgegreys.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TlvMZPLe"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43VtCn4sMkz9s9G for ; Fri, 4 Jan 2019 03:09:41 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=mTxnomY1p/t2Iwi3npHAVQdZBBT6em340TPpma3WAw8=; b=Tlv MZPLeuYRZ36glOHPoOVMnN2D86K5B2Y2K+A1NekdaixVbAQYmlbBVlv7aa9E5Z2S/CF1XGfTAe1Oo dc28DCwm2J2lGoj/nmhXaG7EGzljBOfocTo0Ge0/CxSL1KA80VoYQF/K9gn2TgUxWWbHxsl0Yp32Q YXnZJbh1QhDcibqAddFM4z7neosWl84qM/HmkvSCiE6fDxQ5R4lu6SEryzER1rLhKv9yFe+/L3Qgb 4QdFstUBpIT985lHfJXBY+SLaEIIpmVUIdFnd5py2JGUhafz1xbiEoSwESFvChZrQ2O/7t6QCgkSA Q/JcZ2/gRbVs5lpEcB3SMz/UB0UoJ8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gf5Yr-0001YU-Cb; Thu, 03 Jan 2019 16:09:33 +0000 Received: from ivanoab6.miniserver.com ([5.153.251.140] helo=www.kot-begemot.co.uk) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gf5Yn-0001Y7-By for linux-um@lists.infradead.org; Thu, 03 Jan 2019 16:09:31 +0000 Received: from [192.168.17.6] (helo=smaug.kot-begemot.co.uk) by www.kot-begemot.co.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gf5Yk-0004RJ-7g; Thu, 03 Jan 2019 16:09:26 +0000 Received: from wyvern.kot-begemot.co.uk ([192.168.3.72]) by smaug.kot-begemot.co.uk with esmtp (Exim 4.89) (envelope-from ) id 1gf5Yc-0002Rs-Se; Thu, 03 Jan 2019 16:09:20 +0000 From: anton.ivanov@cambridgegreys.com To: linux-um@lists.infradead.org Subject: [PATCH] um: Try to avoid kmalloc in signal handling Date: Thu, 3 Jan 2019 16:09:17 +0000 Message-Id: <20190103160917.10217-1-anton.ivanov@cambridgegreys.com> X-Mailer: git-send-email 2.11.0 X-Spam-Score: -1.0 X-Spam-Score: -1.0 X-Clacks-Overhead: GNU Terry Pratchett X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190103_080929_542517_55F36102 X-CRM114-Status: GOOD ( 10.31 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, Anton Ivanov MIME-Version: 1.0 Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Anton Ivanov Signal handling (which maps to interrupt handling in UML) needs to pass current registers to the relevant handlers and was allocating a structure for that using kmalloc. It is possible to avoid this kmalloc by using a small "signal register stack". A depth of 4 suffices 99%+ of the time. If it is exceeded further sets of registers are allocated as before via kmalloc. The end result is >10% performance increase in networking as measured by iperf. Signed-off-by: Anton Ivanov --- arch/um/os-Linux/signal.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/um/os-Linux/signal.c b/arch/um/os-Linux/signal.c index bf0acb8aad8b..21536581ab57 100644 --- a/arch/um/os-Linux/signal.c +++ b/arch/um/os-Linux/signal.c @@ -29,14 +29,24 @@ void (*sig_info[NSIG])(int, struct siginfo *, struct uml_pt_regs *) = { [SIGALRM] = timer_handler }; +static int reg_depth; + +static struct uml_pt_regs reg_file[4]; +#define REG_SWITCH_TO_KMALLOC_DEPTH 3 + static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc) { struct uml_pt_regs *r; int save_errno = errno; - r = uml_kmalloc(sizeof(struct uml_pt_regs), UM_GFP_ATOMIC); - if (!r) - panic("out of memory"); + if (reg_depth >= REG_SWITCH_TO_KMALLOC_DEPTH) { + r = uml_kmalloc(sizeof(struct uml_pt_regs), UM_GFP_ATOMIC); + if (!r) + panic("out of memory"); + } else { + r = ®_file[reg_depth]; + } + reg_depth++; r->is_user = 0; if (sig == SIGSEGV) { @@ -53,7 +63,9 @@ static void sig_handler_common(int sig, struct siginfo *si, mcontext_t *mc) errno = save_errno; - free(r); + reg_depth--; + if (reg_depth >= REG_SWITCH_TO_KMALLOC_DEPTH) + free(r); } /*