From: Ulrich Drepper <drepper@redhat.com>
To: SE-Linux <selinux@tycho.nsa.gov>
Subject: libsepol optimization
Date: Tue, 28 Aug 2007 13:08:36 -0700 [thread overview]
Message-ID: <46D480C4.4000801@redhat.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 460 bytes --]
First in a serious or changes proposed for libsepol.
The first is a little patch which shrinks the DSO by 4.3%. The
next_entry and put_entry functions are marked inline. These are not
good candidates, the code is too big. I bet without inlining them the
code actually runs faster because the i-cache isn't so polluted. Plus
the savings in memory of course.
--
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
[-- Attachment #1.2: d-libsepol-uninline --]
[-- Type: text/plain, Size: 2944 bytes --]
diff -durp libsepol-2.0.7/src/private.h libsepol-2.0.7-new/src/private.h
--- libsepol-2.0.7/src/private.h 2007-08-23 13:52:45.000000000 -0700
+++ libsepol-2.0.7-new/src/private.h 2007-08-28 12:26:46.000000000 -0700
@@ -7,6 +7,7 @@
#include <byteswap.h>
#include <endian.h>
#include <errno.h>
+#include <dso.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define cpu_to_le16(x) (x)
@@ -41,52 +42,6 @@ extern struct policydb_compat_info *poli
unsigned int type);
/* Reading from a policy "file". */
-static inline int next_entry(void *buf, struct policy_file *fp, size_t bytes)
-{
- size_t nread;
-
- switch (fp->type) {
- case PF_USE_STDIO:
- nread = fread(buf, bytes, 1, fp->fp);
- if (nread != 1)
- return -1;
- break;
- case PF_USE_MEMORY:
- if (bytes > fp->len)
- return -1;
- memcpy(buf, fp->data, bytes);
- fp->data += bytes;
- fp->len -= bytes;
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-static inline size_t put_entry(const void *ptr, size_t size, size_t n,
- struct policy_file *fp)
-{
- size_t bytes = size * n;
-
- switch (fp->type) {
- case PF_USE_STDIO:
- return fwrite(ptr, size, n, fp->fp);
- case PF_USE_MEMORY:
- if (bytes > fp->len) {
- errno = ENOSPC;
- return 0;
- }
-
- memcpy(fp->data, ptr, bytes);
- fp->data += bytes;
- fp->len -= bytes;
- return n;
- case PF_LEN:
- fp->len += bytes;
- return n;
- default:
- return 0;
- }
- return 0;
-}
+extern int next_entry(void *buf, struct policy_file *fp, size_t bytes) hidden;
+extern size_t put_entry(const void *ptr, size_t size, size_t n,
+ struct policy_file *fp) hidden;
diff -durp libsepol-2.0.7/src/services.c libsepol-2.0.7-new/src/services.c
--- libsepol-2.0.7/src/services.c 2007-08-23 13:52:45.000000000 -0700
+++ libsepol-2.0.7-new/src/services.c 2007-08-28 12:25:58.000000000 -0700
@@ -927,6 +927,58 @@ static int convert_context(sepol_securit
return rc;
}
+/* Reading from a policy "file". */
+int hidden next_entry(void *buf, struct policy_file *fp, size_t bytes)
+{
+ size_t nread;
+
+ switch (fp->type) {
+ case PF_USE_STDIO:
+ nread = fread(buf, bytes, 1, fp->fp);
+
+ if (nread != 1)
+ return -1;
+ break;
+ case PF_USE_MEMORY:
+ if (bytes > fp->len)
+ return -1;
+ memcpy(buf, fp->data, bytes);
+ fp->data += bytes;
+ fp->len -= bytes;
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+size_t hidden put_entry(const void *ptr, size_t size, size_t n,
+ struct policy_file *fp)
+{
+ size_t bytes = size * n;
+
+ switch (fp->type) {
+ case PF_USE_STDIO:
+ return fwrite(ptr, size, n, fp->fp);
+ case PF_USE_MEMORY:
+ if (bytes > fp->len) {
+ errno = ENOSPC;
+ return 0;
+ }
+
+ memcpy(fp->data, ptr, bytes);
+ fp->data += bytes;
+ fp->len -= bytes;
+ return n;
+ case PF_LEN:
+ fp->len += bytes;
+ return n;
+ default:
+ return 0;
+ }
+ return 0;
+}
+
/*
* Read a new set of configuration data from
* a policy database binary representation file.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
reply other threads:[~2007-08-29 16:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46D480C4.4000801@redhat.com \
--to=drepper@redhat.com \
--cc=selinux@tycho.nsa.gov \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.