Commit 8f2215c6 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] uninlining in ipc/*

Uninlines some large functions in the ipc code.

Before:
   text    data     bss     dec     hex filename
  30226     224     192   30642    77b2 ipc/built-in.o

After:
   text    data     bss     dec     hex filename
  20274     224     192   20690    50d2 ipc/built-in.o
parent bb468c02
......@@ -22,6 +22,7 @@
#include <linux/slab.h>
#include <linux/highuid.h>
#include <linux/security.h>
#include <linux/rcupdate.h>
#include <linux/workqueue.h>
#if defined(CONFIG_SYSVIPC)
......@@ -406,6 +407,77 @@ void ipc64_perm_to_ipc_perm (struct ipc64_perm *in, struct ipc_perm *out)
out->seq = in->seq;
}
/*
* ipc_get() requires ipc_ids.sem down, otherwise we need a rmb() here
* to sync with grow_ary();
*
* So far only shm_get_stat() uses ipc_get() via shm_get(). So ipc_get()
* is called with shm_ids.sem locked. Thus a rmb() is not needed here,
* as grow_ary() also requires shm_ids.sem down(for shm).
*
* But if ipc_get() is used in the future without ipc_ids.sem down,
* we need to add a rmb() before accessing the entries array
*/
struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
{
struct kern_ipc_perm* out;
int lid = id % SEQ_MULTIPLIER;
if(lid >= ids->size)
return NULL;
rmb();
out = ids->entries[lid].p;
return out;
}
struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
{
struct kern_ipc_perm* out;
int lid = id % SEQ_MULTIPLIER;
rcu_read_lock();
if(lid >= ids->size) {
rcu_read_unlock();
return NULL;
}
/* we need a barrier here to sync with grow_ary() */
rmb();
out = ids->entries[lid].p;
if(out == NULL) {
rcu_read_unlock();
return NULL;
}
spin_lock(&out->lock);
/* ipc_rmid() may have already freed the ID while ipc_lock
* was spinning: here verify that the structure is still valid
*/
if (out->deleted) {
spin_unlock(&out->lock);
rcu_read_unlock();
return NULL;
}
return out;
}
void ipc_unlock(struct kern_ipc_perm* perm)
{
spin_unlock(&perm->lock);
rcu_read_unlock();
}
int ipc_buildid(struct ipc_ids* ids, int id, int seq)
{
return SEQ_MULTIPLIER*seq + id;
}
int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
{
if(uid/SEQ_MULTIPLIER != ipcp->seq)
return 1;
return 0;
}
#ifndef __ia64__
/**
......
......@@ -4,8 +4,6 @@
*
* ipc helper functions (c) 1999 Manfred Spraul <manfreds@colorfullife.com>
*/
#include <linux/rcupdate.h>
#define USHRT_MAX 0xffff
#define SEQ_MULTIPLIER (IPCMNI)
......@@ -49,76 +47,11 @@ void ipc_free(void* ptr, int size);
void* ipc_rcu_alloc(int size);
void ipc_rcu_free(void* arg, int size);
/*
* ipc_get() requires ipc_ids.sem down, otherwise we need a rmb() here
* to sync with grow_ary();
*
* So far only shm_get_stat() uses ipc_get() via shm_get(). So ipc_get()
* is called with shm_ids.sem locked. Thus a rmb() is not needed here,
* as grow_ary() also requires shm_ids.sem down(for shm).
*
* But if ipc_get() is used in the future without ipc_ids.sem down,
* we need to add a rmb() before accessing the entries array
*/
extern inline struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id)
{
struct kern_ipc_perm* out;
int lid = id % SEQ_MULTIPLIER;
if(lid >= ids->size)
return NULL;
rmb();
out = ids->entries[lid].p;
return out;
}
extern inline struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
{
struct kern_ipc_perm* out;
int lid = id % SEQ_MULTIPLIER;
rcu_read_lock();
if(lid >= ids->size) {
rcu_read_unlock();
return NULL;
}
/* we need a barrier here to sync with grow_ary() */
rmb();
out = ids->entries[lid].p;
if(out == NULL) {
rcu_read_unlock();
return NULL;
}
spin_lock(&out->lock);
/* ipc_rmid() may have already freed the ID while ipc_lock
* was spinning: here verify that the structure is still valid
*/
if (out->deleted) {
spin_unlock(&out->lock);
rcu_read_unlock();
return NULL;
}
return out;
}
extern inline void ipc_unlock(struct kern_ipc_perm* perm)
{
spin_unlock(&perm->lock);
rcu_read_unlock();
}
extern inline int ipc_buildid(struct ipc_ids* ids, int id, int seq)
{
return SEQ_MULTIPLIER*seq + id;
}
extern inline int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid)
{
if(uid/SEQ_MULTIPLIER != ipcp->seq)
return 1;
return 0;
}
struct kern_ipc_perm* ipc_get(struct ipc_ids* ids, int id);
struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id);
void ipc_unlock(struct kern_ipc_perm* perm);
int ipc_buildid(struct ipc_ids* ids, int id, int seq);
int ipc_checkid(struct ipc_ids* ids, struct kern_ipc_perm* ipcp, int uid);
void kernel_to_ipc64_perm(struct kern_ipc_perm *in, struct ipc64_perm *out);
void ipc64_perm_to_ipc_perm(struct ipc64_perm *in, struct ipc_perm *out);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment